Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (2)

后端 未结 1 1893
庸人自扰
庸人自扰 2021-01-25 15:11
declare @xml xml=\'
    
        
            ABC
            Dai         


        
1条回答
  •  野的像风
    2021-01-25 15:42

    Change your query like this:

    SELECT STUFF(
    (
        SELECT '!' + STUFF(p.query(N'for $n in .//*[local-name()!="dailyfrequency"]
                               return {concat("$",($n/text())[1])}'
                            ).value(N'.',N'nvarchar(max)'),1,1,'')
        FROM p.nodes(N'prescription') AS A(p)
        FOR XML PATH(''),TYPE).value(N'.',N'nvarchar(max)'),1,1,'')
    FROM @xml.nodes(N'/plan/prescriptions') AS A(p);
    

    First we create a derived table for the different prescriptions, Secondly we use the former code for each prescription separately.

    0 讨论(0)
提交回复
热议问题