Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I was asked to done a task , i did it but i don't know if it can be done with better way or not.

I have a database table called eventtbl , it has event name , event datetime
I was asked to send mail to all people who going to event before event start datetime with 1 HR
(there are another table for users and another one for users who are going to events)


For example :-

Event name : 2016 Party
Event Date : 2016-01-26 06:00 PM

so if user X and Y subscribed in that , they should get a mail at 2016-01-26 05:00 PM


i did it by creating 2 files , sendmails.sql , sendmails.bat

sendmails.sql => it has a query of sending mails
sendmails.bat => it executes sendmails.sql

and create a job from windows task scheduler to run sendmails.bat every 1 min

every 1 min , query runs ,
i add 1 HR to the current datetime(after remove seconds) and see if the result datetime will match event datetime or not
if yes = >send mails to subscribed users .
if no =>do nothing(there is no event after 1 Hr)

It works fine without any problems , but i need to know if there are better solutions or not.


Thanks
Posted

1 solution

You could consider the option of using the SQL Server Agent to run the task for you. That way you keep everything within SQL Server. In addition SQL Server Agent gives you a few nice options to monitor the task might it fail for some reason and a bit more control over the user executing the T-SQL.
 
Share this answer
 
Comments
Hercal 24-Jan-16 4:53am    
unfortunately , i have sql server express which hasn't feature of sql server agent .
Hercal 24-Jan-16 4:54am    
i mean is there any better solution instead of running the query every min ,
may be run it once a day and send mail at times specified in the query !
but don't know if it possible or not
Member 12001186 11-Feb-16 18:37pm    
I don't see why not ... If there is no need to run the query every minute why should you. Also you could send an email from your script.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900