declare @indextable table(id int identity(1,1),nid int)
set rowcount @endIndex
insert into @indextable(nid) select ID from Info order by ID desc set @sqlStr=@sqlStr + 'select * from Info O, ' + @indextable +' t where O.ID=t.nid
and t.id between ' + @startIndex + ' and ' + @endIndex print @sqlStr请问如上代码,明明已经申明了@indextable ,为什么还报错,要申明标量变量 "@indextable"。呢?
请大家帮帮忙,谢谢了!
set rowcount @endIndex
insert into @indextable(nid) select ID from Info order by ID desc set @sqlStr=@sqlStr + 'select * from Info O, ' + @indextable +' t where O.ID=t.nid
and t.id between ' + @startIndex + ' and ' + @endIndex print @sqlStr请问如上代码,明明已经申明了@indextable ,为什么还报错,要申明标量变量 "@indextable"。呢?
请大家帮帮忙,谢谢了!
用别的办法得到你的结果应该简单很多。
DECLARE @sqlStr NVARCHAR(Max) SELECT @sqlStr=N'declare @indextable table(BrandCode VARCHAR(4))
insert into @indextable(BrandCode)
select BrandCode from Brand order by BrandCode desc
select * from Brand O, @indextable t where O.BrandCode=t.BrandCode'
--and t.id between ' + @startIndex + ' and ' + @endIndex print @sqlStr
EXEC(@sqlStr)