关于 left join 问题 Select * From eit_InfoGroup[a] Left Join (Select CustomTable From eit_ContentModel where id = (select ModelID from eit_infogroup where id=34120))[s] on [a].[Id]=[s].Aid
关联表是动态的,所以得根据 eit_InfoGroup 中的 ModelID 来获取 表明
这样写好像不行啊 ,帮帮忙
------解决方案--------------------
SQL code
(Select CustomTable From eit_ContentModel where id = (select ModelID from eit_infogroup where id=34120))
--你的意思是上面的语句返回的是表的名字??
如果是这样,那么需要动态执行:
declare @tablename varchar(20)
select @tablename=(Select CustomTable From eit_ContentModel where id = (select ModelID from eit_infogroup where id=34120))
exec('Select * From eit_InfoGroup[a] Left Join '+@tablename+' [s] on [a].[Id]=[s].Aid')
------解决方案--------------------