SQL Server 2008 Splitting string variable number of token per line

Posted by josephj1989 on Stack Overflow See other posts from Stack Overflow or by josephj1989
Published on 2010-06-17T20:40:43Z Indexed on 2010/06/17 20:43 UTC
Read the original article Hit count: 466

Filed under:
|

I have a fairly simple requirement -I have a table with the following (relevant) structure.

with cte as(
select 1 id,'AA,AB,AC,AD' names union all
select 2,'BA,BB' union all
select 3,'CA,CB,CC,CD,CE' union all
select 4,'DA,DB,DC'
)

i would like to create a select statement which will split each "names" column into multiple rows.

For example the first row should produce

1,'AA'
1,'AB'
1,'AC'
1,'AD'

Can we do it using only SQL. This is failry easy to do in Oracle.

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server-2008