send email reminder 3 days before deadline...

Posted on 2006-04-19
Last Modified: 2012-06-22
Hi all,

I have got a fieldname called suspenseDate.

This fieldname is usually given a value of  20 days.

This means that if an event occurs today, I have a suspensedate of 20 days to exercise an option.

An email program has been developed to send a reminder to the individual responsible for exercising this option. The email is supposed to go out 3 days before the 20-day deadline elapses, reminding him that he has 3 days left before the 20-day deadline for exercising an option is over.
Is there anything wrong with this code?

So far, no email has been sent even though there are instances where email should have been sent.

SELECT ID, fieldContactName, CONVERT(VarChar,SuspenseDate,101),CONVERT(VarChar,EntryDate,101)
FROM  [Activity]
WHERE CONVERT(VarChar,DateAdd(day,-17,getdate()),101) = CONVERT(VarChar,SuspenseDate,101)
AND receiptDate IS NULL AND Department = 'IT'

Any ideas?
Question by:nigerman
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    you have to specify the size of the varchar for the conversion, otherwise it will not work as expected:
    WHERE CONVERT(VarChar(10),DateAdd(day,-17,getdate()),101) = CONVERT(VarChar(10),SuspenseDate,101)

    Author Comment

    Thanks, Angel.

    I thought that varchar has a variable length.

    Therefore, value takes as much of the length as needed and discards the rest. This appears to be a better choice than char.
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    you are correct, but also varchar has a MAX size.

    now, as you want to compare DATE and not DATE + TIME, you have to limit the string representation of the data value to the date part:

    check out this:
    select convert(varchar(20), getdate(), 101) as long_date_string, convert(varchar(10), getdate(), 101) as short_date_string

    if you keep the time portion, the comparsion will not work as you expect it, as it compares also the time

    Author Comment

    Ok, I think I got your point.

    What you are saying is that if I don't truncate the varchar length for getdate(), it time portion of date value is added.

    Essentially, I would be comparing:

    04/19/2006 (suspensedate) with 04/19/2006 9:47:13 (getdate()).

    This makes eminent sense.

    Thank you!

    Author Comment

    Well, in that case, what is wrong with using CHAR since it only has 10 characters?


    WHERE CONVERT(Char(10),DateAdd(day,-17,getdate()),101) = CONVERT(Char(10),SuspenseDate,101)

    I am asking this because I have used this query too but no results.
    LVL 142

    Accepted Solution

    >Well, in that case, what is wrong with using CHAR since it only has 10 characters?
    there is no difference here, as the values will all be 10 chars long for the comparison.

    just to ensure, the field SuspenseDate is of data type Date?!

    Author Comment

    thank you!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now