Split function that allows multiple character delimiter

Hi I have a table with a varchar column that is delimited by char(227)+char(228)
OrNo=7807ãäSeqNo=1ãäPStopType=PãäPCity=TillsonburgãäPSt=ONãäPZIP=N4G4J1ãäPAdr1=10 ROUSE STREETãäPAdr2=ãäPLat=42.8625ãäPLon=-80.7267ãäDStopType=DãäDCity=GaffneyãäDSt=SCãäDZIP=29341ãäDAdr1=121 PAN AMERICAN DRIVE

would anyone be able to point me to a split function that accepts a multiple character value as a delimter?

Thank you!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
Are you looking for a purely SQL solution, or are you planning on handling the data with a server-side script such as PHP?
Duy PhamFreelance IT ConsultantCommented:
A sample split function in SQL if that is what you are asking for:

CREATE FUNCTION [dbo].[ufn_SplitString](@source NVARCHAR(MAX), @delimiter NVARCHAR(10))
RETURNS @tblSplittedValues TABLE(Item NVARCHAR(200))

	WHILE LEN(@source) > 0
		IF CHARINDEX(@delimiter, @source) > 0
			SET @item = SUBSTRING(@source, 0, CHARINDEX(@delimiter,@source))
			INSERT @tblSplittedValues VALUES(@item)

			SET @source = SUBSTRING(@source, LEN(@item + @delimiter) + 1, LEN(@source))
			INSERT @tblSplittedValues VALUES(@source)
			SET @source = NULL

	-- End function

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scarlett72Author Commented:
Hi Chris, an sql solution would be preferable; however, I would also be able to implement a c# CLR function ...
Duy, I tried your function, it doesn't seem to be splitting for me ...
Vitor MontalvãoMSSQL Senior EngineerCommented:
How do you want to split it?
In many columns?
Or you just want to get rid of those characters and let the value in the same field?
Scarlett72Author Commented:
Hi Duy, I've gone back and re tried your solution as:

declare @delim as varchar(max) = CHAR(227) + CHAR(228)
;with cte as
select colSplit from csvTable
select * from
cte as a
cross apply
dbo.ufn_SplitString(a.colSplit,@delim) as b

and it did end up working, please disregard my original reply, the problem was with how I was applying it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.