This is how you can limit the results from a table based on a parameter's value in non dynamic TSQL
declare @recordCountint = 100
SELECT TOP (@recordCount)
*
FROM MyTableName
All you have to do is not forget the enclosing brackets around the variable in the SELECT TOP clause and it works! Without these brackets you see the following error...
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near '@recordCount'.
No comments:
Post a Comment