如果我運行,select columnA from tableA我會columnA從我的表中獲取值。
如果我運行,select columnB, columnC from tableA as xml path, root我會從格式化為 XML 的 2 列中獲取資料。
我該如何去對上述2個查詢的效果組合成一個讓我回來columnA的,是和columnB同columnC在一個單獨的列標有XML myXml?
我在 SQL2008R2 服務器上運行它。
uj5u.com熱心網友回復:
with myTable as (
select a.columnA,
(select b.columnA, b.columnB
from tableA b
where b.columnA = a.columnA
for xml path, root
) as myXml
from tableA a
)
select * from myTable
我對 XML 如此著迷,以至于我沒有看到我需要在表上使用 2 個別名進行自聯接!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/313212.html
標籤:sql-server xml sql-server-2008
上一篇:萬一宣告更新日期不大于今天日期
