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