我正在使用一个查询,我必须更新一列,因为我有两个查询子集,如下所示:
select a.AuthorId as 'Source_Author',b.AuthorId as 'Target_Author' from (
select d.documentnodeid,AuthorId from wv_blogdata
inner join CMS_Document d on wv_blogdata.BlogDataID = d.DocumentForeignKeyValue
Where DocumentCulture ='en-US') a
INNER JOIN
(select d.documentnodeid,AuthorId from wv_blogdata
inner join CMS_Document d on wv_blogdata.BlogDataID = d.DocumentForeignKeyValue
Where DocumentCulture ='de-DE') b
ON a.documentnodeid =b.documentnodeid
现在我必须用源作者更新目标作者。
答案 0 :(得分:1)
使用公用表表达式
;WITH cteUpdate
AS(
select a.AuthorId as 'Source_Author',b.AuthorId as 'Target_Author'
FROM
(
SELECT d.documentnodeid,AuthorId from wv_blogdata
INNER join CMS_Document d on wv_blogdata.BlogDataID = d.DocumentForeignKeyValue
WHERE DocumentCulture ='en-US'
) a
INNER JOIN
( SELECT d.documentnodeid,AuthorId from wv_blogdata
INNER join CMS_Document d on wv_blogdata.BlogDataID = d.DocumentForeignKeyValue
WHERE DocumentCulture ='de-DE'
) b
ON a.documentnodeid =b.documentnodeid
)
UPDATE
cteUpdate
SET
cteUpdate.Target_Author = cteUpdate.Source_Author