send email reminder 3 days before deadline...

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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
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)
nigermanAuthor Commented:
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.
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

nigermanAuthor Commented:
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!
nigermanAuthor Commented:
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.
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>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?!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nigermanAuthor Commented:
thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.