Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting from xml field

Status
Not open for further replies.

koooob

Programmer
Sep 19, 2007
6
GB
Hi there

can someone help me with a problem - it should be fairly straightforward but I'm a bit new to xml and can't quite find any examples of what I'm trying to do.

in short, I have some xml stored in a database (sql server 2000) and I want to select a field value.

here is some sample code of what I'm trying to do:

Code:
declare @idoc int
exec sp_xml_preparedocument @idoc output, '<items><item><name>geoff</name><id>5</id></item></items>'

select name from openxml (@idoc, '/items/item',2)
--with (name varchar(50))

exec sp_xml_removedocument @idoc

I've pieced this together but I can't just select the name from the record. I'm sure it's straight forward. Any tips on how do I do this correctly?

Thanks in advance!
 
uncomment this line:

--with (name varchar(50))

and try again. It works for me.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Well. That's weird. It does work. I swear it didn't work before I posted. I must have done something weird.

Anyway... thanks for pointing out that it does work!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top