Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

IK1972
Yak Posting Veteran

56 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  
 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