27,580
社区成员
发帖
与我相关
我的任务
分享
declare @sql varchar(8000)
select @sql=isnull(@sql+' union all ','')+' select * from ['+name+']'
from sysobjects where xtype='u' and name like '扩展%'
select @sql = '(' + @sql + ')'
select @sql = 'select a.id,a.x,t.y
from a inner join ' + @sql + ' t on a.id=t.id'
print (@sql)
exec(@sql)
declare @sql varchar(8000)
select @sql=isnull(@sql+' union all ','')+' select * from ['+name+']'
from sysobjects where xtype='u' and name like '扩展%'
select @sql = 'select
a.id,a.x,t.y
from a,' + @sql + ' t where
a.id=t.id'
exec(@sql)
select
a.id,a.x,t.y
from
(select * from 扩展01
union all
select * from 扩展02
union all
select * from 扩展03)t
where
a.id=t.id
left join
select a.id,a.x,y=isnull(isnull(b.y,c.y),d.y)
from 主表 a
left join 扩展01 b on a.id=b.id
left join 扩展02 c on a.id=c.id
left join 扩展03 d on a.id=d.id