Home > Software design >  read from xml string in sql
read from xml string in sql

Time:06-01

i want create stored proc to display last name of xml string ''

so i tried..... following script

Declare @xml_string xml
set @xml_string='<Contacts LastName="jonson"/>'
select Lastname =@xml_string.value('Contacts[1]/LastName[1]','varchar(50)')

select statement display NULL here .please help any one ....

CodePudding user response:

This is the correct way on getting the attribute value from the xml.

Declare @xml_string xml set @xml_string='<Contacts LastName="jonson"/>' 
select Lastname =@xml_string.value('Contacts[1]/@LastName[1]','varchar(50)')
  • Related