bar0822
asked on
t-sql to parse one column
what is the best way to extract data from this column? There could be one or two or three items concatenated with : as a separator. here is sample data:
value = 29826 : 59 : 1 or
value= 29999 : : 1 or
value=29580 : RT : 1 or
value=73560: 59/RT: 1
I need to extract the values from this one column into three separate columns.
thnx,
value = 29826 : 59 : 1 or
value= 29999 : : 1 or
value=29580 : RT : 1 or
value=73560: 59/RT: 1
I need to extract the values from this one column into three separate columns.
thnx,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Agree witj Sharth Solution.
Simple and easy
Simple and easy
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
great. thanks guys you saved me precious time.
ASKER
It was very easy for me to follow since I am a new to SQL. Appreciate this site.
Select columnlist, coalesce([1],'') as columnname1,coalesce([2],'
from (
select x.*,substring(x.[value]+':
,row_number() over (partition by x.primarykeycolumns order by v.number) as rn
from master.dbo.spt_values as v
cross join YOURTABLE as X
Where v.type='p'
and v.number between 1 and len(x.[value])
and substring(':'+x.[value],v.
) as P
pivot (max(part) for rn in ([1].[2],[3])) as pvt
order by ....
if the value column can contain nulls then specify yourtable as
(select columnlist,coalesce([value
if your table primary key is multiple columns
then (partition by pk1,pk2,pk3 order by ...