从Combine multiple rows into one "memo" nvarchar(max)
继续SELECT
DISTINCT fileref, stuff(
(
Select char(13)+char(10) + IsNull( D2.viaccno, '' )
From vi_accno As D2
Where D2.vifileref = A.FileRef
For Xml Path(''), type
).value('.', 'nvarchar(max)')
, 1, 2, '') As accno
FROM
vtindex a
如何使用上述查询更新表1上与fileref = fileref
匹配的每个accno行表1: id,fileref,client,addr,accno
答案 0 :(得分:1)
根据给定的数据,我可以为您提供:
UPDATE t
SET accno = p.accno
FROM [table 1] t
INNER JOIN (
SELECT
DISTINCT fileref, stuff(
(
Select char(13)+char(10) + IsNull( D2.viaccno, '' )
From vi_accno As D2
Where D2.vifileref = A.FileRef
For Xml Path(''), type
).value('.', 'nvarchar(max)')
, 1, 2, '') As accno
FROM
vtindex a
) as p
ON p.fileref= t.fileref