declare @sql varchar(8000)
select @sql=isnull(@sql+' union all ','')+'select f.userid ,u.username,u.address,Convert(char(6),f.cbtdate,112),f.totmoneydx,f.intabmanname from ['+name+'] f left join userinfo00 u on f.userid=u.userid where f.cbtype>0 and f.payyesno=0 '
from sysobjects where xtype='u' and name like 'f20%'or name ='tarrearage'
exec(@sql)
select * into #d from @sql
select @sql=isnull(@sql+' union all ','')+'select f.userid ,u.username,u.address,Convert(char(6),f.cbtdate,112),f.totmoneydx,f.intabmanname from ['+name+'] f left join userinfo00 u on f.userid=u.userid where f.cbtype>0 and f.payyesno=0 '
from sysobjects where xtype='u' and name like 'f20%'or name ='tarrearage'
exec(@sql)
select * into #d from @sql
exec('select * into #d from ('+@sql+') a')
insert into #a exec proc_name
肯定不行的,临时表在动态sql语句中,语句执行后,字段会消失
触发是全局临时表
exec('select * into ##d from ('+@sql+') a')或者
create table #
insert into # exec(@sql)