Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem with Stored Procedure

Author  Topic 

roykauf
Starting Member

36 Posts

Posted - 2008-03-13 : 05:38:31
Hi,

I have a stored procedure that gets a string (ID fields delimitted with a comma) and I want to split so i can use a loop and make an update to table with each ID.

Attached code sample.

Thx for your kind help!


CREATE PROCEDURE spReportAlertSMS
@AlertLogIDList varchar(2000)

AS
Declare @AlertLogID int

BEGIN
IF (SELECT AlertLogID FROM AlertReportLog WHERE AlertLogID = @AlertLogID) <> 0
BEGIN
UPDATE AlerReportLog
SET sms = 1
where AlertLogID = @AlertLogID
END
END
GO

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-13 : 05:50:05
See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Rajender Agarwal
Starting Member

1 Post

Posted - 2008-03-13 : 06:29:02
--Use this to parse the string
Create table #temp ( mailid varchar(50))
Declare @YesorNo bit, @str varchar(8000), @intPatfound int
select @YesorNo=1,
@str='rajender,kumar,agarwal,'
While @YesorNo=1
Begin
Select @intPatfound=charindex( ',' , @str )
Print @intPatfound
--Return
if @intPatfound>0
Begin

Insert into #temp
Select Substring(@str,1,@intPatfound-1)

Select @str=Substring(@str,@intPatfound+1, Len(@str))

Select @YesorNo=1

End
Else
Select @YesorNo=0
End


Select * from #temp
Drop Table #temp


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-03-13 : 08:28:45
http://www.sommarskog.se/arrays-in-sql.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -