declare @top int
set @top = 5
select top @top * from tablename
可能吗?
或者对这样的逻辑有什么想法(我不想使用动态查询)?
最佳答案
是的,在 SQL Server 2005 中,可以在 top
子句中使用变量。
select top (@top) * from tablename
关于sql - 在 SQL Server 的 select 语句中使用带有 TOP 的变量而不使其动态化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1927450/