从日期时间开始在1 HR之前发送邮件。 [英] Sending mails before 1 HR from date time.

查看:128
本文介绍了从日期时间开始在1 HR之前发送邮件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求完成一项任务,我做了但我不知道是否可以用更好的方式完成。



我有一个数据库表名为eventtbl,它有事件名称,事件日期时间

我被要求发送邮件给所有在事件开始日期时间之前参加活动的人,1 HR

(那里)是用户的另一个表,另一个用于去参加活动的用户)





例如: -



活动名称:2016派对

活动日期:2016-01-26 06:00 PM



所以如果用户X和Y订阅了,他们应该在2016-01-26 05:00 PM收到邮件





i是通过创建2个文件来实现的,sendmails.sql,sendmails.bat



sendmails.sql =>它有发送邮件的查询

sendmails.bat =>它执行sendmails.sql



并从Windows任务调度程序创建一个作业,每1分钟运行一次sendmails.bat



每1分钟,查询运行,

i将1个HR加到当前日期时间(删除秒后),看看结果日期时间是否与事件日期时间匹配

if yes =>发送邮件给订阅用户。

如果没有=>什么都不做(1小时后没有活动)



它运行正常没有任何问题,但我需要知道是否有更好的解决方案。





谢谢

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

推荐答案

您可以考虑使用SQL Server代理为您运行任务的选项。这样你就可以保留SQL Server中的所有内容。此外,SQL Server代理为您提供了一些很好的选项来监视任务,可能由于某种原因而失败,并且可以对执行T-SQL的用户进行更多控制。
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.


这篇关于从日期时间开始在1 HR之前发送邮件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆