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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Comma separated to columns

Author  Topic 

vpolasa
Starting Member

1 Post

Posted - 2015-04-10 : 10:39:55
Hi,

I have Oracle query which seperates a text with commas to column data. Can we achieve this in SQL Server?

with t as (select 'abcd,123,defoifcd,87765,aoiwerwe' as str from dual)
select level as n, regexp_substr(str,'[^,]+',1,level) as val
from t
connect by regexp_substr(str,'[^,]+',1,level) is not null;

N VAL
1 abcd
2 123
3 defoifcd
4 87765
5 aoiwerwe

I'm working on SQL Server 2012, Windows 7.

Thanks

MichaelJSQL
Constraint Violating Yak Guru

252 Posts

Posted - 2015-04-10 : 11:06:48
rather than write one - follow this

http://blogs.msdn.com/b/amitjet/archive/2009/12/11/sql-server-comma-separated-string-to-table.aspx
Go to Top of Page
   

- Advertisement -