sql server - Unable to retrieve the Value from the XML from the root element -


i working on xml retrieve data using sql server, not able retrieve correct values query listed below.

declare @xml xml,         @hdoc int set @xml = ' <root>         <a>             <b>name</b>             <y>                 <c>                     <d>m</d>                 </c>             </y>             <e>test1</e>         </a>         <a>             <b>cx</b>             <e>test</e>         </a> </root> ' exec sp_xml_preparedocument @hdoc output, @xml  select a.d, a.b, a.e openxml(@hdoc, 'root/a')  ( d [nvarchar](20) '//y/c/d', b [nvarchar](500) 'b', e [nvarchar](500) 'e' )   -- output of query  d   b   e m   name    test1 m   cx  test 

the problem want corresponding value of <d>, wherever, <d> not provided, return value "m". need value null wherever <d> value not provided.

any appreciated.

select      a.d,      a.b,      a.e openxml(@hdoc, 'root/a')  ( d [nvarchar](20) 'y/c/d', b [nvarchar](500) 'b', e [nvarchar](500) 'e' )  

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -