SQL trigger based on a true/false field value

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2006
Posts: 1
Reputation: andy_mcdougall is an unknown quantity at this point 
Solved Threads: 0
andy_mcdougall andy_mcdougall is offline Offline
Newbie Poster

SQL trigger based on a true/false field value

 
0
  #1
Nov 15th, 2006
Hi,

I have an MS SQL 2000 database with a table that is used to store the header information on product returns. One of the fields in the table is a true/false field that indicates if the return has been processed (become a credit note).

Can anyone tell me how I could go about creating a trigger that would send an email notifying a specific user that this field has been updated from processed=false to processed=true.

To make your eyes bleed a little more, and provide a "why" to this question, when our finance guys process a return and issue a credit note, they then have to switch to their email client and send an email to the internal individual that initiated return process. This takes 11 seconds and leaves the finance guys exhausted. So they have asked if I can automate the process.

Any guidance would be appreciated.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 44
Reputation: MCP is an unknown quantity at this point 
Solved Threads: 3
MCP MCP is offline Offline
Light Poster

Re: SQL trigger based on a true/false field value

 
1
  #2
Nov 16th, 2006
I don't have my sql server readily available, but you could use the "create trigger" command, then use the logical tables "inserted" and "deleted" (which represent what is and what was, respectively) to determine if processed=false in deleted and processed=true in inserted (be sure to handle the case where you have multiple items updated -- even if for a future enhancement that you may not be thinking of). Then you can use xp_sendmail to send the mail -- provided you've got it correctly installed and configured... check books online (SQL Server help) for more info. They have sample code too.

hope this helps.. I just don't have sql server handy to write up a sample..

Originally Posted by andy_mcdougall View Post
Hi,

I have an MS SQL 2000 database with a table that is used to store the header information on product returns. One of the fields in the table is a true/false field that indicates if the return has been processed (become a credit note).

Can anyone tell me how I could go about creating a trigger that would send an email notifying a specific user that this field has been updated from processed=false to processed=true.

To make your eyes bleed a little more, and provide a "why" to this question, when our finance guys process a return and issue a credit note, they then have to switch to their email client and send an email to the internal individual that initiated return process. This takes 11 seconds and leaves the finance guys exhausted. So they have asked if I can automate the process.

Any guidance would be appreciated.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for MS SQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC