Jeff's SQL Server Blog

Random Thoughts & Cartesian Products with Microsoft SQL Server
posts - 155, comments - 2679, trackbacks - 64

My Links



Welcome to my weblog. My name is Jeff Smith, I am software developer in Boston, MA and I was recently named a 2009 SQL Server MVP. Check in frequently for tips, tricks, commentary and ideas on SQL Server and .NET programming.



Post Categories




January 2004 Blog Posts

Using OPENXML to process CSV (comma-separated value) strings

This may be common knowledge to those among us that are handy with XML (I'm not), but since I just uncovered this nice little trick I thought I'd pass it along either way.  It is a very easy way to process a CSV string and turn it into multiple rows: declare @idoc int  -- the handle for the XML documentdeclare @csv varchar(8000) -- the CSV we are being passed set @csv = '1,2,3,7,4,8,10'  -- our list of CSV values -- With a simple edit of the CSV string: set @csv = '' -- We can now do this: EXEC sp_xml_preparedocument @idoc OUTPUT, @csv -- And then: SELECT    *FROM      ...

posted @ Sunday, January 25, 2004 10:01 AM | Feedback (5) | Filed Under [ T-SQL ]

Powered by:
Powered By Subtext Powered By ASP.NET