<p>How can I have a dynamic variable setting the amount of rows to return in SQL Server? Below is not valid syntax in SQL Server 2005+:</p>

<pre><code>DECLARE @count int
SET @count = 20

SELECT TOP @count * FROM SomeTable
</code></pre>

```
```
SELECT TOP (@count) * FROM SomeTable
```
```
This will only work with SQL 2005+