Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

How to display xml attributes in sql syntax with xquery

batteam (Programmer) (OP)
12 Dec 11 10:48
I have the following (snippet) of xml code in a SQL table colum designated as xml datatype.

<RequirementInfo AppliesToPartyID="INS_1_L9019226" FulfillerPartyID="VENDOR_EMSI" id="REQ_L9019226_476043_0000_5">
  <ReqCode tc="5">Collect Urine Specimen (HOS)</ReqCode>
  <RequirementInfoKey>L9019226_476043_0000_5</RequirementInfoKey>
  <RequirementInfoSysKey SystemCode="PLUS" VendorCode="0029">476043</RequirementInfoSysKey>
  <HORequirementRefID>5</HORequirementRefID>
...etc

I can easily pull out the xml element data using the following:

SELECT xml_data.query ('data(//RequirementInfo[1]//ReqCode)') as [XML Sections]
 FROM   dbo.XmlImportTest

My question is, what would the syntax be to read out an ATTRIBUTE in the above xml code snippet, like the tc attribute = "5" in the element 'ReqCode' ??

Thanks for any help you can provide.
batteam (Programmer) (OP)
12 Dec 11 12:38
I found the answer to my own question:

SELECT xml_id, xml_data.query ('data(//RequirementInfo[2]//ReqCode//@tc)') as [XML_Sections]
 
FROM   dbo.XmlImportTest
where xml_id = 3


Regards.

 

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close