Nexus6Studio

mikehouston.net

Quickie How-To for basic usage of xml datatype in SQL2K5

by mhouston 24. July 2007 23:34

This was from an email I sent to some peeps for a quickie how-to...I was told that this kind of junk was worth posting on a blog.  Of course I want to do my part in cluttering up the world...

DECLARE @x as xml
SET @x = '<test att="1">
                  <node1 att="test att val node 1">test data 1</node1>
                  <node1 att="test att val node 2">test data 2</node1>
              </test>' --query a node set like a table
SELECT xd.rows.value('(.)','nvarchar(50)') AS result
FROM   @x.nodes('/test/node1') xd(rows)
--WHERE xd.rows.value('(.)','nvarchar(50)') LIKE '%test data 1'--to get values of attributes and nodes
select @x.value('(/test/@att)[1]', 'int' )--select @x.value('(/test/node1/@att)[1]', 'nvarchar(50)' )
--select @x.value('(/test/node1/@att)[2]', 'nvarchar(50)' )
select @x.value('(/test/node1)[1]', 'nvarchar(50)' )
--select @x.value('(/test/node1)[2]', 'nvarchar(50)' ) --to get nodes/sections/sets/doc fraagments
select @x.query('test/node1')

FYI, the way to dynamically create the xPath statement : use sql:variable to amend the xPath statement - if you try string concats you'll find this out ;-)

Technorati Tags: , , , ,

Currently rated 5.0 by 9 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

, , , ,

SQL | .NET

Related posts

Comments

November 2. 2009 21:08

personal loans

Interesting ... as always - is your blog making any cash advance ? ;)

personal loans us

November 4. 2009 13:57

payday loans

Searching for this for some time now - i guess luck is more advanced than search engines Smile

payday loans us

November 16. 2009 10:17

cash loans

Searching for this for some time now - i guess luck is more advanced than search engines Smile

cash loans us

November 20. 2009 21:56

fast payday loans

Just wanted to say thanks for this.

fast payday loans us

November 29. 2009 10:24

cash advance

as they say - A barking dog never bites

cash advance us

November 30. 2009 06:51

Acai Berry

Pretty Interesting post. Couldnt be written any better. Reading this post reminds me of my old room mate! He always kept talking about this. I will forward this post to him. Pretty sure he will have a good read. Thanks for sharing!

Acai Berry us

December 5. 2009 16:49

Reverse Cell Phone Lookup

Never seen such cool post. I read it all the way to the end. Keep them coming.

Reverse Cell Phone Lookup us

December 6. 2009 15:03

product reviews

Thats an interesting post. It was worth visiting your blog. Hope to visit again.

product reviews us

December 7. 2009 13:58

Fat Loss 4 Idiots Review

WOW your page came up first in Google. And this is what I was looking for.

Fat Loss 4 Idiots Review us

December 7. 2009 23:50

payday loans

I like what I see. keep it going

payday loans us

December 8. 2009 22:33

Registry Easy

Looks like an interesting blog. Will make visit again.

Registry Easy us

December 9. 2009 15:44

Speed up windows xp

Loved reading this post.

Speed up windows xp us

December 13. 2009 04:36

Fat Loss 4 Idiots

Although I do agree with your post, I have my own reservations.

Fat Loss 4 Idiots us

December 18. 2009 10:00

Cooking Chili Recipes

When I originally commented I clicked the "Notify me when new comments are added" checkbox and now each time a comment is added I get four emails with the same comment.
Is there any way you can remove me from that service?
Thanks!

Cooking Chili Recipes us

December 18. 2009 10:48

Cheese Pizza Recipes

This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work.

Cheese Pizza Recipes us

December 20. 2009 21:18

us online casinos

Hi webmaster, commenters and everybody else !!! The blog was absolutely fantastic! Lots of great information and inspiration, both of which we all need!b Keep 'em coming... you all do such a great job at such Concepts... can't tell you how much I, for one appreciate all you do!

us online casinos us

December 20. 2009 23:08

where to buy fioricet

This is a really good read for me, Must admit that you are one of the best bloggers I ever saw.Thanks for posting this informative article.

where to buy fioricet us

December 21. 2009 01:19

us online casinos jes

The blog was absolutely fantastic! Lots of great information and inspiration, both of which we all need!

us online casinos jes us

December 21. 2009 01:29

usa online casinos

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It's always nice when you can not only be informed, but also entertained! I'm sure you had fun writing this article.

usa online casinos us

December 21. 2009 01:40

us online casinos

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon.

us online casinos us

December 22. 2009 11:11

ben cummings

Nice to be visiting your blog again, it has been months for me. Well this article that i've been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share.

ben cummings us

December 22. 2009 11:20

meridian idaho real estate

I was wondering what is up with that weird gravatar??? I know 5am is early and I'm not looking my best at that hour, but I hope I don't look like this! I might however make that face if I'm asked to do 100 pushups. lol

meridian idaho real estate us

December 22. 2009 12:14

seo software

This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work.

seo software us

December 22. 2009 13:36

jump manual

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon.

jump manual us

December 23. 2009 04:00

matt le baron

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.

matt le baron us

Sign in
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent any of my associates' views in anyway.
“A foolish consistency is the hobgoblin of little minds, adored by little statesmen and philosophers and divines. With consistency a great soul has simply nothing to do. He may as well concern himself with his shadow on the wall. Speak what you think now in hard words, and tomorrow say what tomorrow thinks in hard words again, though it contradict everything you say today. "Ah, so you shall be sure to be misunderstood." Is it so bad, then, to be misunderstood? Pythagoras was misunderstood, and Jesus and Socrates and Luther and Copernicus and Galileo and Newton, and every pure and wise spirit that ever took flesh. To be great is to be misunderstood.” - Ralph Waldo Emerson
© Copyright 2010 Nexus6Studio & Mike Houston