declare @i int
set @i=1declare @value intwhile(@i<=(select count(*) from dbo.BA_LoopInfoDetails))
begin
select top 1 * from dbo.BA_LoopInfoDetails where lidid not in (select top @i lidid from dbo.BA_LoopInfoDetails)
set @i=@i+1
end提示: '@i' 附近有语法错误。这句该怎么写呢?
set @i=1declare @value intwhile(@i<=(select count(*) from dbo.BA_LoopInfoDetails))
begin
select top 1 * from dbo.BA_LoopInfoDetails where lidid not in (select top @i lidid from dbo.BA_LoopInfoDetails)
set @i=@i+1
end提示: '@i' 附近有语法错误。这句该怎么写呢?
set @i=1 declare @value int while(@i <=(select count(*) from dbo.BA_LoopInfoDetails))
begin
select top 1 * from dbo.BA_LoopInfoDetails where lidid not in (select top (@i) lidid from dbo.BA_LoopInfoDetails)
set @i=@i+1
end
然后 exec @sql
begin
DECLARE @SQL VARCHAR(4000)
SET @SQL='select top 1 * from dbo.BA_LoopInfoDetails where
lidid not in (select top '+LTRIM(@i)+' lidid from dbo.BA_LoopInfoDetails)')
EXEC(@SQL)
set @i=@i+1
end
begin
DECLARE @SQL VARCHAR(4000)
SET @SQL='select top 1 * from dbo.BA_LoopInfoDetails where
lidid not in (select top '+LTRIM(@i)+' lidid from dbo.BA_LoopInfoDetails)'
EXEC(@SQL)
set @i=@i+1
end
需要拼字符串