I have a query to be run in one IAM tool where we are comparing last passwordchangedate and now.
i just needs to know whether below query will throw error if we pass null value inside DATEDIFF()?
SELECT DISTINCT
u.username AS UName,
u.statuskey AS SK,
CASE
WHEN DATEDIFF(NOW(), u.createdate) >= 30
AND DATEDIFF(Now(),a.LASTPASSWORDCHANGE) <= 30
AND u.customproperty18 !='Y'
AND u.customproperty63 IS NULL THEN 'Inactive'
ELSE u.customproperty17
END AS CP17
FROM
users u
WHERE
((DATEDIFF(Now(),u.createdate) > 30
AND DATEDIFF(Now(),a.LASTPASSWORDCHANGE) <= 30
i just needs to know what will happen if we pass null in DATEDIFF and what is solution for this.
what i needs to modify in my above query
2
Answers
No. The documentation explicitly tells that
So the case when the argument value is NULL is a regular feature and not an error. Neither an error nor a warning is generated. And your progran won’t receive any signal that it’d throw an exception.
Use a wrapper of condition statement for NULL Date validation as follows:
I think it should work.
Thank you