split string in sql

How can I split a String at "," if it exists?

lastname, firstname

Doe, john

or it could be just name of a business

Bank of American
VBdotnet2005Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
EmesConnect With a Mentor Commented:
declare @names varchar(100)
set @names ='My,Name'


if charindex(',', @names) <> 0
  Select substring(@names,1, charindex(',', @names) -1),
    substring(@names, charindex(',', @names) +1,100)
0
 
VBdotnet2005Author Commented:
What if a string does not contain ","?   Bank of American

Command(s) completed successfully.  it does not return anything.
0
 
VBdotnet2005Author Commented:
I got it. Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.