Splitting csv to columns

Published 15 March 08 09:10 AM | Madhivanan 

Suppose you have string in csv format and want to split into seperate columns. You can use parsename function as long as you have maximum four values. The following would work for any number of values

declare @s varchar(2000),@data varchar(2000)

select @s='this,is,test'

select @data=''''+replace(@s,',',''',''')+''''

exec('select '+@data)

Comments

# SQL Server Transact-SQL (SSQA.net) : Splitting csv to columns said on March 15, 2008 4:20 AM:

PingBack from http://sqlserver-qa.net/blogs/t-sql/archive/2008/03/15/3811.aspx

# Other SQL Server Blogs around the Web said on March 15, 2008 5:10 AM:

Suppose you have string in csv format and want to split into seperate columns. You can use parsename

Anonymous comments are disabled

Search

Go

This Blog

«March 2008»
SMTWTFS
2425262728291
2345678
9101112131415
16171819202122
23242526272829
303112345

Syndication