Sometimes, with top n middle n It is a variable that will need to be used () to complete:
DECLARE @count1 intset @count1 = 8select top <strong> (@count1) </strong> * from MyTable
Assuming that the same effect can be achieved with SET ROWCOUNT
DECLARE @count1 intset @count1 = 8 Set RowCount @count1select * from MyTable
But be careful. Using SET rowcount has side effects, once set. The subsequent statements will affect the. and SQL Server changes this in the likely version number. So be careful with it.
Important NOTES: |
In the next version number of SQL Server, using set ROWCOUNT will not affect the DELETE, INSERT, and UPDATE statements. In the new development work. Avoid using the SET ROWCOUNT statement with the DELETE, INSERT, and UPDATE statements, and plan to change the application that currently uses the statement. In addition, for DELETE, INSERT, and UPDATE statements that are currently using SET ROWCOUNT, it is recommended that you rewrite them using the TOP syntax. For specific information, see DELETE (Transact-SQL), INSERT (Transact-SQL), or UPDATE (Transact-SQL). |
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
Set RowCount and Top n