Re: Comparing dates

From: Aaron Bertrand - MVP (aaron_at_TRASHaspfaq.com)
Date: 05/14/04


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.


Relevant Pages

  • Search for calculated duplicate using worksheet events - Possible?
    ... If the totals within any group are duplicates of a previous total ... want just a warning). ... check their entry. ... 4 5 Trigger a message to double check the entry ...
    (microsoft.public.excel.programming)
  • Re: MoveAfterReturn is tricking me.
    ... The argument Target in the Worksheet_Change event tells you what cell ... > I've got the first column of my worksheet checking to see if the ... > first character of the typed entry is a string or a number. ... > Because of the way that the event trigger seems to work, ...
    (microsoft.public.excel.programming)
  • Re: Can this be done with a trigger?
    ... inserted or updated it will make the entry to the history table. ... the problem is the 'SOURCE' column on the history table. ... fires the trigger to make the second entry. ... All I can think of is to update the record from the PL/SQL ...
    (comp.databases.oracle.misc)
  • RE: Newbie help emailing a blob field
    ... Haven't read all of this but to get the new info join to the table from the ... > application that emails a message to the assigned people when the ... I've tried an instead of on the trigger with no luck. ... > left outer join InVision_dta.dbo.tblUserDefDate tblUserDefDate ...
    (microsoft.public.sqlserver.programming)
  • Re: Can this be done with a trigger?
    ... inserted or updated it will make the entry to the history table. ... the problem is the 'SOURCE' column on the history table. ... I am trying to write the trigger. ... All I can think of is to update the record from the PL/SQL ...
    (comp.databases.oracle.misc)