我有一个包含2个ID的2列表,每对都是唯一的。我很想找到一种方法来为第一列IE的每个实例创建一个以逗号分隔的列表:
IDcolumn1value1 | IDColumn2value1, IDColumn2Value2, IDColumn2Value3; IDcolumn1value2 | IDcolumn2Value2, IDcolumn2Value4
我可以创建一个游标,并迭代IDcolum1中的每一个项目,但是假设有~8k对,那可能效率不高。
目前我有:
DECLARE @listStr VARCHAR(MAX)
SELECT @listStr = COALESCE(@listStr+',' , '') + Component_Softpaq.SoftpaqNumber
FROM Softpaq_SKU INNER JOIN
ComponentVersion ON Softpaq_SKU.ComponentVersionID = ComponentVersion.ComponentVersionID INNER JOIN
ComponentPass ON ComponentVersion.ComponentVersionID = ComponentPass.ComponentVersionID INNER JOIN
Component_Softpaq ON ComponentPass.ComponentPassID = Component_Softpaq.ComponentPassID
group by Softpaq_SKU.SKUID, Component_Softpaq.SoftpaqNumber
SELECT @listStr