Click here to Skip to main content
15,895,799 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...


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

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))
end
Posted

1 solution

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

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648[^]

You will get data in a table which you can join with your main table to get the required output.
 
Share this answer
 
Comments
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