Click here to Skip to main content
14,694,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I Want to split the string which contains '1,2,'....which contains in ProgrammId column.. I declared programmid as varchar in stored procedure but in table structure it is declared as int.... So help me i am struck with the query...

while charindex(',',@PROGRAMID) <> 0
DECLARE @var1 nvarchar(30)

select @var1=substring(@PROGRAMID,1,(charindex(',',@PROGRAMID)-1))

INSERT INTO dbo.Table_ProgramJoinDetails(ProgramId ,UserId,programjoindate,programenddate,Slotid)VALUES  (@var1 ,@USERID,@slot,@slot1,@Slotid)
   --select ProgramId from Table_ProgramJoinDetails where ProgramId=CAST(@var1 AS int)

SET @PROGRAMID = substring(@PROGRAMID,charindex(',',@PROGRAMID)+1,len(@PROGRAMID))

1 solution

You can use any of the split functions from the following thread:[^]

You will get data in a table which you can join with your main table to get the required output.
Unareshraju 22-May-12 1:34am
yes prakash good url

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900