how can split a strin in sql using comaa delimiter
thanks in advance
How can split a string in sql using comma delimiter
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Prabhu RajaRank #861 · 2.6K reputationPosted Sep 1, 2011, 12:55 AM EDT
try this codes
CREATE FUNCTION dbo.Split(@String varchar(8000), @Delimiter char(1))
returns @temptable TABLE (items varchar(8000))
as
begin
declare @idx int
declare @slice varchar(8000)
select @idx = 1
if len(@String)<1 or @String is null return
while @idx!= 0
begin
set @idx = charindex(@Delimiter,@String)
if @idx!=0
set @slice = left(@String,@idx - 1)
else
set @slice = @String
if(len(@slice)>0)
insert into @temptable(Items) values(@slice)
set @String = right(@String,len(@String) - @idx)
if len(@String) = 0 break
end
return
end
and run this function as
select * from dbo.split('Chennai,Bangalore,Mumbai',',')
you will get output as,
Chennai
Bangalore
Mumbai
Thank you
Vilas GiteRank #951 · 2.1K reputationPosted Sep 1, 2011, 10:59 PM EDT
Same thread here…
http://social.msdn.microsoft.com/forums/en-US/transactsql/thread/4126a010-6885-4eb0-b79c-c798c90edb85
And, if you want split String in C# then you can refer good one article of Mahesh Sir: http://www.c-sharpcorner.com/UploadFile/mahesh/2890/ ------------------------------------------------------------------------------
If this reply helps your post…then check "This is correct answer"