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 |
|
helixpoint
Constraint Violating Yak Guru
291 Posts |
Posted - 2009-04-08 : 17:01:37
|
| I need to loop threw records and grab the data to send out emails in the stored proc. How do I do this?DaveHelixpoint Web Developmenthttp://www.helixpoint.com |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-04-08 : 17:12:59
|
| using a cursor. But if you post more on this, sample data, output etc etc, we might be able to suggest a set based approach. |
 |
|
|
helixpoint
Constraint Violating Yak Guru
291 Posts |
Posted - 2009-04-08 : 17:42:54
|
| Does not seem to loopALTER PROCEDURE [dbo].[sendHelixMail] ASBEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON;Declare firstQuery Cursor forSELECT BatchSchedule.emailAddFROM BatchEmailSchedule INNER JOIN BatchSchedule ON BatchEmailSchedule.batchID = BatchSchedule.batchIDWHERE (BatchEmailSchedule.emailDate <= GETDATE())for Read Only;Declare @emailAdd nvarchar(75);Open firstQuery;Fetch Next from firstQuery Into @emailAdd;WHILE (@@fetch_status <> -1) print @emailAddclose firstQuery;deAllocate firstQuery;ENDDaveHelixpoint Web Developmenthttp://www.helixpoint.com |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-04-08 : 17:59:30
|
try if it loops with this,ALTER PROCEDURE [dbo].[sendHelixMail] ASBEGIN-- SET NOCOUNT ON added to prevent extra result sets from-- interfering with SELECT statements.SET NOCOUNT ON;Declare firstQuery Cursor forSELECT BatchSchedule.emailAddFROM BatchEmailSchedule INNER JOINBatchSchedule ON BatchEmailSchedule.batchID = BatchSchedule.batchIDWHERE (BatchEmailSchedule.emailDate <= GETDATE())for Read Only;Declare @emailAdd nvarchar(75);Open firstQuery;Fetch Next from firstQuery Into @emailAdd;WHILE (@@fetch_status <> -1) beginprint @emailAddFetch Next from firstQuery Into @emailAdd;endclose firstQuery;deAllocate firstQuery;END |
 |
|
|
|
|
|