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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

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

kdeutsch
Yak Posting Veteran

USA
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
BEGIN
--- 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'
END
set rowCount = 1

visakh16
Very Important crosS Applying yaK Herder

India
52326 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
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next 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.06 seconds. Powered By: Snitz Forums 2000