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
 [SQL] Makin columns from one column

Author  Topic 

deathrone
Starting Member

15 Posts

Posted - 2013-06-07 : 09:32:39
Hey,
I have a column for example like this:

'blabla','bum',0,50,0
'bbb', 'pach',0,100,9

how to put dat every world into seprate column?
so to make it perfectly clear I wanna 5 columns sth like this:

blabla | bum | 0 | 50 | 0
bbb . | pach| 0 | 100| 9

trololoolo

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-07 : 10:35:50
do like

SELECT MAX(CASE WHEN f.ID = 1 THEN REPLACE(f.Val,'''','') END) AS Part1,
MAX(CASE WHEN f.ID = 2 THEN REPLACE(f.Val,'''','') END) AS Part2,
MAX(CASE WHEN f.ID = 3 THEN f.Val END) AS Part3,
MAX(CASE WHEN f.ID = 4 THEN f.Val END) AS Part4,
MAX(CASE WHEN f.ID = 5 THEN f.Val END) AS Part5
FROM YourTable t
CROSS APPLY dbo.ParseValues(t.YourCol,',')f
GROUP BY t.YourCol


ParseValues can be found in below link

http://visakhm.blogspot.in/2010/02/parsing-delimited-string.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -