How do I programmatically limit the number of rows in MS SQL?

I would like to be able to limit the number of rows using a variable. SELECT TOP only allows integer, so SELECT TOP @RowLimit is invalid.

Related tags: MSSQL

Credit: Original Poster

You can do this by using the rowcount keyword as follows:

SET ROWCOUNT @RowLimit



After the query, set rowcount back to 0

SET ROWCOUNT 0

Rating: 1

Propose a different solution...