Hi
I want to use ms sql 2005 to send email reminders to my customers. I want to send daily reminders that should run around midnight(when traffic would be low).
So I think the best way to do this is through ms sql 2005 and I been looking into sql agent and database mail but I am unsure how to make a script that would dynamically get the information for each customer(each customer will have a different email sent to them).
So I need to query one table to get everyone email address, I need a query to get that customers info that I am planning to send.
Once I have this information I then need to then format the email and send them(so if I have 50 customers - 50 different customized emails will be sent out).
To: Always different person, From: static probably won't change, Title- probably will be always different, Body - Always different.
My body always will require it to be html since I will be using html tags.
So can someone give me a watered down example to get started? I am not that that great with databases and have not used ms sql 2005 very much.
I think I need sql agent as it can do it at set times, and of course database mail to send it all away.
But after that it is a big blank. I saw this post
http://blog.netnerds.net/2008/02/create-a-basic-sql-server-2005-trigger-to-send-e-mail-alerts/
but she is using triggers so I don't know if I have to use this in combination as well.
Edit
Here is some tables I am trying to keep them simple so I can understand what is going on and probably will be different then my end result.
Table A
id - pk - incrementing int
email - varchar(20)
Table B
TableBId - pk - incrementing int
id - fk
title - varchar(30)
body - varchar(2000)
SendOutDate - datetime
type - varchar(5)
Sample Data
Table A
Id email
------------------
1 [email protected]
2 [email protected]
3 [email protected]
Table B
TableBId Id title body sendoutDate type
---------------------------------------------------------------------------
1 1 Reminder1 <b>test</b> 12/24/2010 12:30 pm Email
2 1 Reminder2 hello 12/25/2010 12:30 pm Email
3 1 Reminder3 hi text 12/28/2010 11:30 pm SMS
4 1 Reminder4 again 12/29/2010 5:00am Both
5 2 Your Reminder test 12/24/2010 2:30 am Email
6 3 jim bo 12/25/2010 11:59:59 pm SMS
Ok so a couple things to note in future version I want to support sending out Email and SMS alerts so they would be in the same table just with a different type. "Both" meaning "Email and SMS" alert would be sent out.
Of course right now lets just stick with Email alerts but I wanted to show you the whole story but I am assuming these would be 2 different operations so a where clause probably will be needed.
Next the time date. I want to send out notification around midnight so midnight to midnight should be 24 hours.
So if we from December 24th 12am to December 25th 12pm all notifications in this range should be sent out then the next day would be Dec 25th to Dec 26th and so on.
I am also guessing a join would be needed to join Table A and B together. Then I would need to grab the data out and put it in some variables or something.
So how could I write this sp? KM was saying I need to loop over some stuff or something like that. I am guessing I have to write some sql type forloop then?