SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL XML
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

IK1972
Yak Posting Veteran

54 Posts

Posted - 11/02/2012 :  22:35:02  Show Profile  Reply with Quote

I have data in one xml column

<LTW>
<Arrtibute Level="PR" name="ST" type="Include" Value="'CA','NY'" />
<Arrtibute Level="LN" name="LA" type="LessThan" Value="500000" />
</LTW>

I want to create function who return table in this format.

Level name type Value
PR ST include 'CA','NY'
LN LA LessThan 500000

Thanks

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/03/2012 :  08:38:12  Show Profile  Reply with Quote
You can wrap the query below into a function. You may get better performance if you directly used the query against your table(s) instead of wrapping them in functions.
DECLARE @x XML = '<LTW> 
<Arrtibute Level="PR" name="ST" type="Include" Value="''CA'',''NY''" />
<Arrtibute Level="LN" name="LA" type="LessThan" Value="500000" /> 
</LTW>';

SELECT
	c.value('@Level','varchar(32)') [Level],
	c.value('@name','varchar(32)') [name],
	c.value('@type','varchar(32)') [type],
	c.value('@Value','varchar(32)') [Value]
FROM
	@x.nodes('/LTW/Arrtibute') T(c);
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000