Hello All,
I have Xml In that Root Element Consist of 1 Level Child Element ,I am able to get values using apply cross shown below like, "b.x.value('/CustomData[1]/Teens[1]', 'varchar(100)') as TeenID",
But Root Element Consist of 2 level in that I have Some tags , I want to Access those tags same ways as 1 Level element,I tried different ways ,unable to get those Values ,
Ex:- Below Query I am able get the Teens,
same way , I want IsScholarship and AmountPaid tags value it inside Payment Tag, here OrderItemCustomData is Column of COM_OrderItem table it Consist of Xml Data ,as given Below .
COM_OrderItem is consist of mother 1 Row .
Query :-
SELECT
b.x.value('/CustomData[1]/Teens[1]', 'varchar(100)') as TeenID,
b.x.value('/CustomData[1]/IsScholarship[1]', 'bool') as IsScholarship,
b.x.value('/CustomData[1]/totalDueAmount[1]', 'varchar(100)') as DueAmount
b.x.value('/CustomData[1]/AmountPaid[1]','varchar(100)')as AmountPaid
FROM
COM_OrderItem a
CROSS APPLY (
SELECT
CAST([OrderItemCustomData] AS XML) x
) b
XML:-
<?xml version="1.0" encoding="utf-16"?>
<CustomData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Teens>442406</Teens>
<Payment>
<AmountPaid>75</AmountPaid>
<DueAmount>0</DueAmount>
<PaidDate>2013-02-06T00:00:00</PaidDate>
<PaidBy>442406</PaidBy>
<IsTeen>true</IsTeen>
<PaidPaymentType>CreditCard</PaidPaymentType>
<PaidTo>442406</PaidTo>
<TransactionID>4991186053</TransactionID>
<Notes />
<IsScholarship>false</IsScholarship>
<ScholarshipAppliedDate xsi:nil="true" />
</Payment>
<Payment>
<AmountPaid>149</AmountPaid>
<DueAmount>-75</DueAmount>
<PaidDate>2014-04-03T00:00:00</PaidDate>
<PaidBy>442406</PaidBy>
<IsTeen>true</IsTeen>
<PaidPaymentType>CreditCard</PaidPaymentType>
<PaidTo>442406</PaidTo>
<TransactionID>6065829864</TransactionID>
<Notes />
<IsScholarship>false</IsScholarship>
<ScholarshipAppliedDate xsi:nil="true" />
</Payment>
<DueAmount>-75</DueAmount>
<TotalDueAmount>0</TotalDueAmount>
<TotalRefundAmount>75</TotalRefundAmount>
</CustomData>
Please help me out ,to achieve the same
Thanks in advance.