We help IT Professionals succeed at work.

MSSQL Select records "x" days after stored date

mandi224
mandi224 used Ask the Experts™
on
I have a table that has users' email addresses, an integer field that is number of days in which to email them a reminder, and a datetime field that is the date the record was added, something like this:

ID    Email          ReminderInDays                    DateAdded
1   xyz@test.com          30                    2012-03-15 11:00:39.483
2   abc@test.com          120                    2012-04-02 08:00:49.217
3   def@test.com          60                     2012-04-02 08:02:27.573

Open in new window


I need to be able to run a query and get all the emails that should be sent a reminder, so basically selecting all emails for which the number of "ReminderInDays" has past since "DateAdded"
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011
Commented:
Please try:
Select * from TheTable
where dateadd(day, ReminderInDays, DateAdded) < getdate()

Open in new window

Author

Commented:
Perfect! Thank you. I knew it would be something simple, but my brain wasn't wrapping around it this morning. Thanks for the help.