当前位置: 代码迷 >> Sql Server >> ms-sql数据库变量和top之间的组合有关问题
  详细解决方案

ms-sql数据库变量和top之间的组合有关问题

热度:31   发布时间:2016-04-27 14:33:34.0
ms-sql数据库变量和top之间的组合问题
declare @num int
declare @ind int
declare @name int
set @ind=0
select @num=count(*) from 职工 where 仓库号 in('wh1','wh4')
while(@num>0)
begin
exec('select top 1 职工ID as ' + @name + ' from 职工 where 仓库号 in(''wh1'',''wh4'') and 职工ID not in(select top ' + @ind + ' 职工ID from 职工 where 仓库号 in(''wh1'',''wh4''))')
set @ind = @ind+1
set @[email protected]
end
看下面这一语句出现问题了,拜求~
exec('select top 1 职工ID as [email protected]+' from 职工')


------解决方案--------------------

SQL code
declare @n int, @sql nvarchar(400) set @sql='select top 1 @a=id from tb' exec sp_executesql @sql,[email protected] int output',@n output select @n
  相关解决方案