Select Top 后面能否跟参数
我下面的存储过程是错误的,那位帮我解决一下
Create Procedure GetSpecial
---@top_sp Int
As
Declare @top_sp int
Set @top_sp = 49
Select top '+@top_sp+' * From Special --就是这里说语法不对呀
GO
...全文
4178打赏收藏
Select Top 后面能否跟参数???帮我解决
Select Top 后面能否跟参数 我下面的存储过程是错误的,那位帮我解决一下 Create Procedure GetSpecial ---@top_sp Int As Declare @top_sp int Set @top_sp = 49 Select top '+@top_sp+' * From Special --就是这里说语法不对呀 GO
declare @sql nvarchar(1000)
declare @top_sp int
set @top_sp=5
select @sql='select top '+convert(nvarchar(10),@top_sp) +' * from special'
exec sp_executesql @sql
我试过了,没问题
Create Procedure GetSpecial
---@top_sp Int
As
Declare @top_sp int
Set @top_sp = 49
exec( 'Select top '+ cast(@top_sp as varchar(10)) +' * From Special') --就是这里说语法不对呀
改一下就可以了
Create Procedure GetSpecial
---@top_sp Int
As
Declare @SQL varchar(200)
Declare @top_sp varchar(200)
Set @top_sp = '49'
set @sql='Select top '
set @sql=@sql+@top_sp+' * From Special'