sql - Table from comma separated Column at two level -


i have 1 old db in there 2 columns contain comma separated values this,

table schema data

sql fiddle link schema

now problem trying import values database normalized. instead of comma separated values, need convert values tabular format .

so output should this,

enter image description here

you need define columns mean. in example discarding original id column, in case "1,2,3" & "a,b" mean?

i'd approach cursoring through each row , using split function convert each field table of values.

create function dbo.fn_split1 (@sep nchar(1), @s nvarchar(4000)) returns table /**************************************************************************************************  * author:              http://stackoverflow.com/questions/314824/  * description:         splits string table of values, single-char delimiter.  * example usage:          select * dbo.fn_split1(',', '1,2,5,2,,dggsfdsg,456,df,1,2,5,2,,dggsfdsg,456,df,1,2,5,2,,')  **************************************************************************************************/ return (     pieces(pn, start, stop) (       select 1, 1, charindex(@sep, @s)       union       select pn + 1, stop + 1, charindex(@sep, @s, stop + 1)       pieces       stop > 0     )     select pn,       substring(@s, start, case when stop > 0 stop-start else 4000 end) s     pieces   ) 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -