Tags: sql, sql server 2008, sql server 2005, tsql, sql server, ms sql, ms sql server, t-sql, sqllserver, top, mssql,
You dont need dynamic SQL
SELECT TOP(@var) is valid syntax
Thanks for reply. I have mentioned #1 way which you said.
Please note that SET ROWCOUNT is a deprecated feature from SQL 11 ("Denali") onwards for the INSERT/UPDATE and DELETE statements. You can still continue to use it for SELECT statements as is demonstrated in this post.
Does the numbering system imply the preferred method to select top records?
Thanks for nice article.
Btw. Your examples have no ORDER BY clause. TOP without ORDER BY is confusing, because data are unordered and results could be wrong.