Click here to Skip to main content
14,299,038 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello All,

I have a value in one column like '12345-1234'... I have to split this string and put in different columns.

Can anyone help me on this...

Output is like below

12345
1234

Thanks In Advance...

Regards,
Naveen
Posted
Comments
nilesh sawardekar 19-Jul-14 3:24am
   
Is it serialize .. i mean to say 12345-1234-12345-1234.and so on?
Rate this:
Please Sign up or sign in to vote.

Solution 1

Try this:
SELECT LEFT(columnname, Charindex('-', columnname) - 1) as leftcolumn,
       RIGHT(columnname, Charindex('-', Reverse(columnname)) - 1)  as rightcolumn
FROM table1
   
Comments
NaVeN Kumar 21-Jul-14 4:36am
   
Perfect thanks for the solution Peter... :)
Peter Leow 21-Jul-14 10:51am
   
You are welcome.
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hi Naven,

check this Query

SELECT LEFT(id, CHARINDEX('-',id)-1) as ID1,   
 RIGHT(id, CHARINDEX('-',id) - 2)  as ID2
FROM [Table_2]


ID1	ID2
12345	1234

thanks
   
v3
Comments
NaVeN Kumar 21-Jul-14 4:41am
   
Thanks for the solution Vani Suresh, but it is not working for all formats...

If I have given 12345-123 then I got like below

ID1 ID2
12345 -123

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100