dllhell
dllhell

Reputation: 2014

How to limit rows in select using parameter

I would like to set limit for selected rows using parameter but obviously I can't write something like:

select top @count * from tbl

Also, I'm not very happy about turning select into string like:

exec('select top ' + casttovarchar(@count) + ' * from tbl')

Question: Is it posible and how to parametrize select top?

Upvotes: 0

Views: 414

Answers (1)

J.M Smith
J.M Smith

Reputation: 391

It is possible using brackets:

select top (@count) * from tbl 

Upvotes: 3

Related Questions