你写的肯定有问题,还没有生成呢怎么能from #tt

解决方案 »

  1.   

    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
      

  2.   

    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
    能看到
      

  3.   

    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.合同号')
    ------------------------------
    或者像二楼的用全局临时表