Not getting XML Parsed values using Nodes Method in SQL Server?

I’m trying parse and get values of below xml with following code, But I’m not able to get the values it’s returning empty or NULL values.

What I’m missing in my xml parsing code?

   declare @AddressXML as xml = '<Address>
  <Details FkTypeOfAddress="1" Address1="gh" Address2="yu" Address3="gh" Landmark="gh" City="Kolkata" Pincode="777777" State="ARU" />
  <Details FkTypeOfAddress="2" Address1="io" Address2="io" Address3="io" Landmark="io" City="Kolkata" Pincode="999999" State="GOA" />
</Address>'

SELECT    [Table].[Column].value('(FkTypeOfAddress) [1]','BIGINT') as FkTypeOfAddress
                        ,[Table].[Column].value('(Address1) [1]','varchar(100)') as Address1
                        ,[Table].[Column].value('(Address2) [1]','varchar(100)') as Address2 
                        ,[Table].[Column].value('(Address3) [1]','varchar(100)') as Address3
                        ,[Table].[Column].value('(Landmark) [1]','varchar(200)') as Landmark
                        ,[Table].[Column].value('(City) [1]','varchar(100)') as City
                        ,[Table].[Column].value('(Pincode) [1]','varchar(10)') as Pincode
                        ,[Table].[Column].value('(State) [1]','varchar(50)') as [State]                     
               FROM      @AddressXML.nodes('/Address/Details') as  [Table]([Column]);

enter image description here


Source: xml

Leave a Reply