如何使用参数限制select中的行

时间:2016-12-22 08:51:18

标签: sql-server tsql

我想使用参数设置所选行的限制,但显然我不能写如下:

select top @count * from tbl

另外,我对将select变为字符串感到不满意:

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

问题:它是否可行以及如何参数化select top

1 个答案:

答案 0 :(得分:2)

可以使用括号:

select top (@count) * from tbl