I have a dynamic query, and i am using exec command in stored procedure to execute it.
now i want to extract only Top 10 rows from result of executed query.
i can't modify the query, i want to extract from the result only
This is the query i am executing.
DECLARE @Str nvarchar(max)
SET @str = 'SELECT *
FROM tblC6FD_QueryBuilderMaster'
EXEC (@str)
how can i limit the results without modify the actually query
Thanks
Selecting a top n records for each category from any table, can be done easily using row_number function which generates a sequential integer to each row within a partition of a result set.
So, if you want to see the top 10 products, we can use the TOP Clause and extract the required number of rows.
To select first 10 elements from a database using SQL ORDER BY clause with LIMIT 10. Insert some records in the table using insert command. Display all records from the table using select statement.
Use ROWCOUNT:
DECLARE @Str nvarchar(max)
SET @str = 'SELECT * FROM tblC6FD_QueryBuilderMaster'
SET ROWCOUNT 10
EXEC (@str)
SET ROWCOUNT 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With