Jayar Tan Baldoza
Jayar Tan Baldoza

Reputation: 13

DateDiff every 3 days

I want to know if you know how to date diff every 3 days im doing scheduler.

SELECT DISTINCT 
    CLAIM_NO,
    ModifiedBy,
    ClaimType,
    ClaimStatus,
    EmailAddress,
FROM EP_ADMIN_ITEM_REMINDER
WHERE Status = 1 AND DATEDIFF(Day,DateAdded,getdate()) = 3

This is my code in DATEDIFF i put into WHERE Clause I have 2 columns for date 1st DateAdded 2nd DateSent. I need to schedule my thing every 3 days so it will update the datesent first and it will check if the datesent is Greterthan the dateadded into 3. I just want to know if my WHERE clause is correct. thanks

Upvotes: 1

Views: 1038

Answers (2)

Ben Thul
Ben Thul

Reputation: 32707

Keep SARGability in mind. Specifically, running a function like you have can degrade performance (I don't remember if DATEDIFF is optimized for this or not) because it has to run it for every row. Try

WHERE [DateAdded] > DATEADD(day, -3, getdate())

Upvotes: 2

Chhatrapati Sharma
Chhatrapati Sharma

Reputation: 623

SELECT DISTINCT 
CLAIM_NO,
ModifiedBy,
ClaimType,
ClaimStatus,
EmailAddress,
FROM EP_ADMIN_ITEM_REMINDER
WHERE Status = 1 AND DATEDIFF(Day,DateAdded,getdate()) > 2

Upvotes: 6

Related Questions