让我说我有一个查询,在一列中,我将一组返回的项目与每个项目之间的插入符分隔符填充在一起,并且当返回的项目数少于时,重复分隔符。 10(总分为9分,不论总项数)。
SELECT
so.Client_Name + '|' +
STUFF((SELECT '^' + CAST(SUB.itemId AS VARCHAR(25)) AS [text()]
FROM Table_1 SUB
WHERE SUB.clientId = so.clientId AND SUB.repID = so.repId AND SUB.orderPlaced = 0
FOR XML PATH('')
), 1, 1, '' ) AS 'col1'
FROM Table_1 so
返回类似于:
的内容Test Client|Item_1^Item_2^Item_3^Item_4^Item_5^Item_6^Item_7^Item_8^Item_9^Item_10^Item_11^Item_12^Item_13
Client Two|Item_1^Item_2^Item_3^Item_4^Item_5^Item_6^Item_7^Item_8^Item_9^Item_10^Item_11^Item_12^Item_13^Item_14^Item_15
我需要:
Test Client|Item_1^Item_2^Item_3^Item_4^Item_5^Item_6^Item_7^Item_8^Item_9^Item_10
Test Client|Item_11^Item_12^Item_13^^^^^^
Client Two|Item_1^Item_2^Item_3^Item_4^Item_5^Item_6^Item_7^Item_8^Item_9^Item_10
Client Two|Item_11^Item_12^Item_13^Item_14^Item_15^^^^^
等等......