declare @sql nvarchar(4000) set @sql='select '+@update_fieds+'b.海关代号,b.车型号,b.合同号,b.合同余额 into #AA from #tt a left join table_合同执行余额查询 b on a.海关代号=b.海关代号 and a.车型号=b.车型号 and a.合同号=b.合同号' exec sp_executesql @sql select * from ##AA drop table ##AA
exec('select '+@update_fieds+'b.海关代号,b.车型号,b.合同号,b.合同余额 into #ttfrom #tt a left join table_合同执行余额查询 b on a.海关代号=b.海关代号 and a.车型号=b.车型号 and a.合同号=b.合同号') 这时候以经在#tt表里有数据了 select * from #tt 能看到
create table #AA(col1 varchar(10),.....) insert #AA exec('select '+@update_fieds+'b.海关代号,b.车型号,b.合同号,b.合同余额 from #tt a left join table_合同执行余额查询 b on a.海关代号=b.海关代号 and a.车型号=b.车型号 and a.合同号=b.合同号') ------------------------------ 或者像二楼的用全局临时表
set @sql='select '+@update_fieds+'b.海关代号,b.车型号,b.合同号,b.合同余额 into #AA from #tt a left join table_合同执行余额查询 b on a.海关代号=b.海关代号
and a.车型号=b.车型号 and a.合同号=b.合同号'
exec sp_executesql @sql
select * from ##AA
drop table ##AA
and a.车型号=b.车型号 and a.合同号=b.合同号')
这时候以经在#tt表里有数据了
select * from #tt
能看到
insert #AA
exec('select '+@update_fieds+'b.海关代号,b.车型号,b.合同号,b.合同余额 from #tt a left join table_合同执行余额查询 b on a.海关代号=b.海关代号
and a.车型号=b.车型号 and a.合同号=b.合同号')
------------------------------
或者像二楼的用全局临时表