Re: Comparing dates
From: Aaron Bertrand - MVP (aaron_at_TRASHaspfaq.com)
Date: 05/14/04
- Next message: Alicia: "RE: Comparing dates"
- Previous message: Christiaan: "Re: setting foreign key to null when deleting primary key"
- In reply to: D Mack: "Comparing dates"
- Next in thread: Alicia: "RE: Comparing dates"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 14 May 2004 12:13:46 -0400
Is the "entry date" a DATETIME or SMALLDATETIME column?
You can say
IF EXISTS (SELECT 1 FROM Inserted WHERE EntryDateColumnName >= {fn
CURDATE()}
AND EntryDateColumnName < DATEADD(DAY, 1, {fn CURDATE()})
-- send e-mail
Be aware that this will send an e-mail even if your update statement affects
10 rows and only one of them meets the criteria.
Do you really need to know that such a row was added, immediately after it
was added? Is once a day, or once every four hours, enough? You might wish
to go the route of a background job that scans the table and alerts you when
there are new rows... then you don't kill your performance with a trigger...
-- Aaron Bertrand SQL Server MVP http://www.aspfaq.com/ "D Mack" <anonymous@discussions.microsoft.com> wrote in message news:EB35F43C-B440-476B-B106-71FADA247CB3@microsoft.com... > I have a trigger that sends emails based on updating a table. The problem is, it sends too many emails. It will send an email whenever the record is updated and I don't like that. I need to modify the trigger so it compares the date a record was entered to today's date. If today's date is equal to the entry date (just mm/dd is preferable but mm/dd/yyyy will work) then it executes an email. If it is not equal, it deletes a temporary record. > > How do I - > 1. format the date > 2. compare the two dates > > Thanks.
- Next message: Alicia: "RE: Comparing dates"
- Previous message: Christiaan: "Re: setting foreign key to null when deleting primary key"
- In reply to: D Mack: "Comparing dates"
- Next in thread: Alicia: "RE: Comparing dates"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|