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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 While loop

Author  Topic 

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2013-05-30 : 12:58:58
Trying to figure out how to loop threw sql

select name, email from tableOne

then loop.....
EXEC msdb.dbo.sp_send_dbmail
@profile_name = @name,
@recipients = @email ,
@body = 'The stored procedure finished successfully.',
@subject = 'Automated Success Message' ;


Dave
Helixpoint Web Development
http://www.helixpoint.com

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-05-30 : 13:45:29
Why do you want to loop it? The body message shows that you want to send an email when ever a/the stored procedure is compelted/finsihed.. If so why not simply append this send email logic at the end of that SP? or somewhere in the code once the SP execution is successful ?

by the way, example of the while loop is as following

declare @x int
set @x=0
while @x<>10
begin
print @x
set @x=@x+1
End

Cheers
MIK
Go to Top of Page

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2013-05-30 : 14:26:25
The select bring back multiple records

Dave
Helixpoint Web Development
http://www.helixpoint.com
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-05-30 : 14:38:35
quote:
Originally posted by helixpoint

The select bring back multiple records

Dave
Helixpoint Web Development
http://www.helixpoint.com



what does it mean? what select bring back multiple records??

Cheers
MIK
Go to Top of Page

djj55
Constraint Violating Yak Guru

352 Posts

Posted - 2013-05-30 : 15:49:07
Is what you are trying to do, read a table of names then send an email to each name from that table? If so look at DECLARE CURSOR in BOL.

djj
Go to Top of Page
   

- Advertisement -