0

I need to find out first 1000 rows of a table without using top and rowcount. I must use where clause in my query. The query should look like this :

select * from <table_name> where <condition>

I do not have any good column that can be used in where clause.

Also I can't add a new column.

Neo
  • 93
  • 1
  • 12

1 Answers1

0

Using row_number with a literal value in the order by might be the solution you're looking for.

with n as (
    SELECT 
        neo.* 
        , ROW_NUMBER() OVER (ORDER BY (SELECT 100)) as [rn]
    FROM <table_name> neo
) 
SELECT 
    n.*
FROM n 
WHERE n.[rn] <= 1000 -- first 1000 rows
GlennFriesen
  • 302
  • 4
  • 15
  • Cant chnage the select clause as well. Only thing I can input is the condition which will be added by the application after "where" – Neo May 16 '16 at 20:17
  • @Neo Can you share what the column names of your tables are, along with some sample data? BTW, it seems very strange that you're unable to only input the condition after the WHERE ... why is that? – GlennFriesen May 18 '16 at 15:58