How to Split aafter comma and display in new Row
i have empid as 1,2,5,3,4
and i want to split and display as
1
2
5
3
4
with emnpname
1=a
2=b
3=c
.........................
please help
Loading
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
Jignesh TrivediRank #16 · 50.3K reputationPosted Oct 8, 2013, 12:29 AM EDT
hi,
if you are SQL server 2008 and above user, split function is inbuilt.
http://technet.microsoft.com/en-us/library/aa496058%28v=sql.80%29.aspx
you can also modify this function as per your requirement.
Khargesh RajputRank #616 · 3.9K reputationPosted Oct 7, 2013, 9:43 PM EDT
ALTER FUNCTION [dbo].[Split]
(
@RowData nvarchar(2000),
@SplitOn nvarchar(5)
)
RETURNS @RtnValue table
(
Id int identity(1,1),
Data nvarchar(100)
)
AS
BEGIN
Declare @Cnt int
Set @Cnt = 1
While (Charindex(@SplitOn,@RowData)>0)
Begin
Insert Into @RtnValue (data)
Select
Data = ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))
Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))
Set @Cnt = @Cnt + 1
End
Insert Into @RtnValue (data)
Select Data = ltrim(rtrim(@RowData))
Return
END
but how to use with query in join
Puneet GuptaRank #2,006 · 724 reputationPosted Oct 8, 2013, 12:27 AM EDT
http://www.webtechminer.com/split-function-in-sql-server-to-break-comma-separated-string/
Thanks,
Puneet Gupta
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Oct 8, 2013, 12:37 AM EDT