T-SQL問題,需要幫助
declare @counts int,@sql varchar(100)
set @counts=1
set @sql= 'select * into #tmp from (select top '+str(@counts)+ ' [id],mainmenu from db_main_menu) s '
--select @sql as slq
exec(@sql)
select * from #tmp
請問為什麼會提示#tmp不存在呢?我應該如何寫才能在存儲過程中直接調用?謝謝
------解决方案--------------------这样那 ?
declare @counts int,@sql varchar(100)
set @counts=1
set @sql= 'select * into #tmp from (select top '+str(@counts)+ ' [id],mainmenu from db_main_menu) s '
set @sql=@sql+ ';select * from #tmp '
exec(@sql)
------解决方案--------------------你的语句要一起运行才能体现出来!#临时表在运行一个批次语句将被删除!
------解决方案--------------------同意楼上的
------解决方案--------------------declare @counts int,@sql varchar(100)
set @counts=1
set @sql= 'select * into ##tmp from (select top '+str(@counts)+ ' [id],mainmenu from db_main_menu) s '
--select @sql as slq
exec(@sql)
select * from ##tmp
要不这样,换成全局的