如何在select top query中使用Parameter [英] How to use Parameter in select top query
本文介绍了如何在select top query中使用Parameter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在select top查询中使用参数lke this
声明@Tot_10 int
从Incentive_0_3_BD顺序中选择Top @Total FPG FPG
How to use Parameter in select top query lke this
declare @Tot_10 int
select Top @Total FPG from Incentive_0_3_BD order by FPG
推荐答案
DECLARE @Total INT
SET @Total = 2
select Top (@Total) FPG from Incentive_0_3_BD order by FPG
将其设为动态查询。
Make it a dynamic query.
declare @mysql varchar(max)
declare @topCount varchar(4)
set @topCount='5'
set @mysql='select top ' + @topCount + '* from TABLE_NAME'
exec(@mysql)
你不能直接这样做:
You can't do it directly:
declare @Tot_10 int
DECLARE @myCommand NVARCHAR(1024)
SET @myCommand = 'select Top ' + CAST(@Tot_10 AS NVARCHAR) + 'FPG from Incentive_0_3_BD order by FPG'
EXECUTE (@myCommand)
这篇关于如何在select top query中使用Parameter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文