34,576
社区成员
发帖
与我相关
我的任务
分享
-->try
select a.费用ID,
a.费用名称,
a.PrimaryKeyId,
b.TableName,
b.PrimaryName
from 费用表 a,系统表 b
where a.Sys_ModuleID=b.Sys_ModuleID
declare @tab table(ID int,name varchar(30))
declare @sql varchar(max)
select @sql=(select qs+' union all ' from
(
select 'select '+b.PrimaryName+','+ltrim(a.费用ID)+' ID
from '+b.TableName+'
where '+ltrim(b.PrimaryKeyId)+'='''+ltrim(a.PrimaryKeyId)+'''' qs
from 费用表 a,系统表 b
where a.Sys_ModuleID=b.Sys_ModuleID
)t)
insert into @tab
exec(@sql)
select a.费用ID,a.费用名称,a.Sys_ModuleID,a.PrimaryKeyId,b.name
from 费用表 a,@tab b
where a.费用ID=b.ID