Apr192013

Use a Parameter with SELECT TOP in T-SQL

A quick T-SQL tip to end the week with: T-SQL's SELECT TOP can accept a parameter to choose how many rows to select:

DECLARE @TopLimit INT = 100

SELECT TOP (@TopLimit) FROM YOURTABLE yt

The parentheses around the parameter are important; don't forget them!