Solved

split string in sql

Posted on 2013-01-14
3
400 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
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
Emes earned 500 total points
Comment Utility
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
Comment Utility
What if a string does not contain ","?   Bank of American

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

Author Comment

by:VBdotnet2005
Comment Utility
I got it. Thank you
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now