临时表@tb如何从临时表里面取出 前面 的 几百条语句这个 top 数据 是动态的top 100 或者
top 200 或者
top 300 或者
top 400
这种语句定义了一个临时表@tb了,并且里面语句有数据@str='select top '+str(@count)+'.........请问这句要怎么写??我这里怎么总是提示:必须声明标量变量 "@tb"exec(@str)
top 200 或者
top 300 或者
top 400
这种语句定义了一个临时表@tb了,并且里面语句有数据@str='select top '+str(@count)+'.........请问这句要怎么写??我这里怎么总是提示:必须声明标量变量 "@tb"exec(@str)
(
id int
)
declare @i int;
set @i=0
while @i<1000
begin
insert into #tb values(@i);
set @i=@i+1;
endselect top(100)* from #tb
create proc aaa
@count int
as
begin
select top(@count)* from #tb
end
exec aaa 100
--试试这个是你要的结果不是
declare @sql as nvarchar(4000)
declare @count as int
set @count=100 --200,300,400
set @sql=' declare @tb table(id int,[name] nvarchar(10))'+ --把这里改成你的临时表@tb 的定义
' insert @tb select * from table '+ --把这里改成你的insert 语句
' select top '+left(@count)+' from @T'
exec(@sql)