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 6 people

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

, , , ,

SQL | .NET

More Pics from Cabo

by mhouston 17. July 2007 05:31

IMG_0169

IMG_0087

IMG_0088 

Technorati Tags: , , ,

Currently rated 5.0 by 1 people

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

, , ,

Misc | Travel

Golf in Cabo was nice!!

by mhouston 15. July 2007 22:28

IMG_0141

IMG_0140

Technorati Tags: , , ,

Currently rated 5.0 by 2 people

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

, , ,

Travel | Golf

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 2008 Nexus6Studio & Mike Houston