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.
| 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)ASDeclare @AlertLogID intBEGIN IF (SELECT AlertLogID FROM AlertReportLog WHERE AlertLogID = @AlertLogID) <> 0 BEGIN UPDATE AlerReportLog SET sms = 1 where AlertLogID = @AlertLogID ENDENDGO |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
Rajender Agarwal
Starting Member
1 Post |
Posted - 2008-03-13 : 06:29:02
|
| --Use this to parse the stringCreate table #temp ( mailid varchar(50))Declare @YesorNo bit, @str varchar(8000), @intPatfound intselect @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 #tempDrop Table #temp |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-03-13 : 08:28:45
|
| http://www.sommarskog.se/arrays-in-sql.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|