SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Loop through record set
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

83 Posts

Posted - 01/24/2013 :  11:28:46  Show Profile  Reply with Quote
Trying to lopp through my temp table to send out emails to indivduals, does note seem to work. what am i doing wrong.

set rowcount 0

Select @Name = Name, @Email = Email, @Idate = IssueDt, @Rdate = TurnIN, @Days = DaysOver from #TempEmail;

While @@rowcount <> 0
--- do send the email here ...
Set @Subject = 'Temporary Issue is Overdue'
Set @Body = 'The following item of equipment temporarily issued on {' + @Idate + '}.' + ' ' + 'The equipment was due on {' + @Rdate + '} and is overdue by {' + @Days + '} Days.' + Char(13) + Char(10) +
'Please return the equipment or make arrangements to keep equipment longer.' + Char(13) + Char(10) + 'SN = '

EXEC msdb.dbo.sp_send_dbmail
@recipients = @To,
@body = @Body,
@subject = @Subject,
@profile_name = 'ACN'
set rowCount = 1

Very Important crosS Applying yaK Herder

52325 Posts

Posted - 01/25/2013 :  00:59:47  Show Profile  Reply with Quote
it will just send a single mail under current logic. As you've not written iterative logic to fetch next records from table.
The first select just takes a random set of values from table to variables.

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000