我在sql server数据库中有一个Process表,如下所示:
如果Process
中存在Rolename
,我需要选择RoleTable
,如下所示:
select ID,WorkflowXML
from
(
select m.c.value('@RoleName','nvarchar(max)') as Rolename,p.*
from Process as p
outer apply p.WorkflowXML.nodes('/workflow/Tasks/Task[@type="start"]/TaskUsers/TaskUser') as m(c)
) as Pro where Pro.Rolename in
(SELECT * from RoleTable)
在此选择中Rolename
添加到Process
。我只需要Process
表。我可以添加Process
个字段(ID,WorkflowXML
)进行查询。如果我更改Process
表格设计,我应该编辑查询。这不是很好。
有没有办法在查询中选择Process
表而不添加像这样的Process
字段?
select Pro
from
(
select m.c.value('@RoleName','nvarchar(max)') as Rolename,p.*
from Process as p
outer apply p.WorkflowXML.nodes('/workflow/Tasks/Task[@type="start"]/TaskUsers/TaskUser') as m(c)
) as Pro where Pro.Rolename in
(SELECT * from RoleTable)
感谢。
答案 0 :(得分:1)
您可以加入此表格,如:
select p.*
from Process as p
outer apply p.WorkflowXML.nodes('/Tasks/Task[@type="start"]/TaskUsers/TaskUser') as m(c)
INNER JOIN RoleTable r
ON r.Rolename = m.c.value('@RoleName','varchar(max)')