Solved

split string in sql

Posted on 2013-01-14
3
408 Views
Last Modified: 2013-01-14
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
0
Comment
Question by:VBdotnet2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
Emes earned 500 total points
ID: 38775001
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
 

Author Comment

by:VBdotnet2005
ID: 38775039
What if a string does not contain ","?   Bank of American

Command(s) completed successfully.  it does not return anything.
0
 

Author Comment

by:VBdotnet2005
ID: 38775064
I got it. Thank you
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question