Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extract top 10 from results without modifying the actual query

Tags:

sql-server

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

like image 299
M Akela Avatar asked Aug 12 '13 11:08

M Akela


People also ask

How do you SELECT Top 10 records from each category in SQL Server?

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.

Which of the following queries will you use to extract only the top 10 items?

So, if you want to see the top 10 products, we can use the TOP Clause and extract the required number of rows.

How do I SELECT top 10 rows in MySQL?

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.


1 Answers

Use ROWCOUNT:

DECLARE @Str nvarchar(max)
SET @str = 'SELECT * FROM tblC6FD_QueryBuilderMaster'

SET ROWCOUNT 10
EXEC (@str)
SET ROWCOUNT 0
like image 75
eKek0 Avatar answered Sep 27 '22 21:09

eKek0