sql help with inspection

I am trying to create an alert for the managers when the cars are due for inspection. There are 2 fields inspectiondate and nextinspectiondate that are responsible for the inspection. The alert need to be triggered 30 days before its expire .

SELECT 1 as 'Due for Inspection',
c.carNumber,
C.nextinspectiondate,C.inspectiondate,
C.model,c.carnumber,c.make,c.modelyear,
isNUll(DATEDIFF(DAY,GETDATE(),c.nextinspectiondate),0) as Next,
isNull(DATEDIFF(DAY,GETDATE(),c.inspectiondate),0) as Curr

FROM CAR C
   		WHERE C.carActiveIn = 1
   		--and DATEDIFF(DAY,GETDATE(),c.nextinspectiondate) > 0 OR DATEDIFF(DAY,GETDATE(),c.inspectiondate)  > 0
   		ORDER BY C.carKey

Open in new window

LVL 19
erikTsomikSystem Architect, CF programmer Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
The dateDiff is correct, but you need to check for exact 30 days (= 30), or less or equal to 30 (<= 30) if you want to get the alert each day.
0
PortletPaulEE Topic AdvisorCommented:
and use parentheses with the OR condition, like this:

WHERE C.carActiveIn = 1
AND (
      DATEDIFF(DAY, GETDATE(), c.nextinspectiondate) <= 30
   OR DATEDIFF(DAY, GETDATE(), c.inspectiondate) <= 30
    )

Open in new window

0

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
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
Query Syntax

From novice to tech pro — start learning today.