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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sql 2008 query trigger email to user

Author  Topic 

hpham
Starting Member

1 Post

Posted - 2013-08-06 : 17:06:25
Hi,

I need to trigger an email to user when a work order due date is approaching 1 day prior to the due date. Also I need to trigger when a user adds, delete, or modify work order to check on work order due.

Not sure how to query it in SQL. Thanks in advance.

Due Date = NeedByDate
user = AssignedTo

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-08-07 : 00:31:21
You can add a sql server agent job for checking this. Get details of all users from table using given condition. something like

DECLARE @EmailList varchar(max)

SET @EmailList = STUFF((SELECT ';' + emailAddress
FROM UserTable u
INNER JOIN WorkOrder o
ON o.UserID = u.UserID
WHERE WorkOrderDueDate >= DATEADD(dd,DATEDIFF(dd,0,GETDATE()),1)
AND WorkOrderDueDate < DATEADD(dd,DATEDIFF(dd,0,GETDATE()),2)
FOR XML PATH('')),1,1,'')

then call sp_send_dbmail to send the email to list generated above
http://technet.microsoft.com/en-us/library/ms190307.aspx


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -