0
XML我有一個這樣的碼用於從多個行使用在SQL
輸入串接值:
ID Name
------------- ----------------------
1 Deepak Kumar Goyal
2 Niladri Biswas
2 Priyanka Sarkar
3 Sumi Girijan
3 Suresh Beldar
3 Jeeva Baby
預期輸出:使用
ID Name
------- --------------------------------------------------
1 Deepak Kumar Goyal
2 Niladri Biswas OR Priyanka Sarkar
3 Sumi Girijan AND Suresh Beldar AND Jeeva Baby
查詢:
select ID, SUBSTRING(
(
select ','+CAST(name AS VARCHAR)
from @t a where a.ID = b.ID
FOR XML PATH('')
),2,2000) as names
from @t b group by id
查詢成功運行。你能幫我理解這裏的XML的必要性以及它的工作原理和工作原理嗎?
如果您發佈的代碼,XML或數據樣本,** **請在高亮文本編輯器這些線路上,並點擊了「代碼示例」按鈕('{}')編輯器工具欄可以很好地格式化和語法突出顯示它! – 2011-05-05 06:43:34