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
 split string to columns

Author  Topic 

eugz
Posting Yak Master

210 Posts

Posted - 2012-02-27 : 12:38:46
Hi All.

I have string:

2638 ABA, DDA COMM YES 001213 01 1295760 AA6272 YES D
2650 BBADI, JJJJHEED COMM NO 001360 01 1477530 NO D

How to split it to the columns? And if is it possible I would like split to columns ABA, DDA and BBADI, JJJJHEED?

Thanks.

X002548
Not Just a Number

15586 Posts

Posted - 2012-02-27 : 12:51:45
Does your columns you want to split always start in the second column and the last value to split after there are no more commas?

Where did you get this mess from in the first place?

Is the file delimited by something (space, tab,???)



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

eugz
Posting Yak Master

210 Posts

Posted - 2012-02-27 : 16:03:58
Thanks for replay.

I found that sample:
'Doe, John'

SELECT SUBSTRING('Doe, John',0,CHARINDEX(',','Doe, John')) AS LastName,

SUBSTRING('Doe, John',CHARINDEX(',','Doe, John')+1,len('Doe, John')) AS Firstname

But how to split to LastName FirstName MI if string is 'Doe, John N'?

Thanks.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-27 : 19:26:36
in the latter case what should be first and lastname?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -