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

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Loop to automate emails to list of contacts
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

DCW87
Starting Member

6 Posts

Posted - 06/21/2012 :  10:45:35  Show Profile  Reply with Quote
hey guys,

Can anyone advise me as to how to create a loop which will send an email to a list of contacts?

for example, i have a contacts table (FK to another tables contacts_ID) and a table which contains a workload. I also have a script which works pefectly for a single user whereby i can send an email via MS alongisde an XLS extract of the workload. How do i create a job to do this for each unique contact ID in the workload table??

Here's the email syntax:

EXEC msdb.dbo.sp_send_dbmail
@recipients=dave@me.com,
@body= 'Here's your workload',
@subject = '@User workload',
@profile_name = 'SQL Mail',
@execute_query_database = 'DB',
@query ='select query (will be based on a contact ID variable),

@attach_query_result_as_file = 1;

Thanks in advance!
  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