在 SQL Server 的 select 语句中使用带有 TOP 的变量而不使其动态 [英] Use variable with TOP in select statement in SQL Server without making it dynamic
本文介绍了在 SQL Server 的 select 语句中使用带有 TOP 的变量而不使其动态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
declare @top int
set @top = 5
select top @top * from tablename
有可能吗?
或者对这种逻辑有什么想法(我不想使用动态查询)?
Or any idea for such a logic (i don't want to use dynamic query)?
推荐答案
是的,在 SQL Server 2005 中,可以在 top
子句中使用变量.
Yes, in SQL Server 2005 it's possible to use a variable in the top
clause.
select top (@top) * from tablename
这篇关于在 SQL Server 的 select 语句中使用带有 TOP 的变量而不使其动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文