Click here to Skip to main content
14,271,759 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi all


can any body tell me how can i split the string ,

i want something like this

given string 'sachin,rahul'

i want this result 'sachin', 'rahul'


tx in advance
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

DECLARE @FullName        VARCHAR(100)
SET @FullName = 'John,Doe'

SELECT SUBSTRING(@FullName, 1, CHARINDEX(',', @FullName) - 1) AS [FirstName],
       SUBSTRING(@FullName, CHARINDEX(',', @FullName) + 1, LEN(@FullName)) AS [LastName]


More Examples:

http://www.sql-server-helper.com/tips/split-name.aspx[^]
   
Comments
thatraja 24-Nov-11 13:59pm
   
Right, 5!
Rate this:
Please Sign up or sign in to vote.

Solution 2

Here other alternative ways

Split string in SQL[^]
   

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