大家好,我一直在尝试将以下代码的结果插入名为 dbo.filemetadata.Source 的列中,这是代码:
WITH CTE AS
(
SELECT
rn,
ROW_NUMBER() OVER (PARTITION BY rn ORDER BY (SELECT NULL)) filepartno,
Split.a.value('.', 'VARCHAR(100)') AS filepart
FROM
(
SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) rn,
CAST ('<M>' + REPLACE(FilePath, '\', '</M><M>') + '</M>' AS XML) AS String
FROM FileMetadata
) AS A
CROSS APPLY String.nodes ('/M') AS Split(a)
)
SELECT FilePart AS A
FROM CTE C
JOIN (SELECT MAX(filepartno) maxfilepartno, rn
FROM CTE
GROUP BY rn) C2 ON C.rn = C2.rn AND C.filepartno = C2.maxfilepartno-1;