ashwin ashwin - 1 month ago 18
SQL Question

Minimum inside Date Difference

I have 3 fields A , B and C in MS Access Table named TBL. I am trying to find the date difference in hours using Date difference function. I want to find the date difference between minimum of fields A, B and field C. I tried to achieve it using the following code

SELECT Datediff("h",Min(A,B),C) FROM TBL


The above function gives me an error with wrong number of arguments used with function in query expression. How can I achieve the above

Answer

You could use IIF for this:

SELECT IIF(DATEDIFF("h", A, C) < DATEDIFF("h", B, C),
           DATEDIFF("h", A, C),
           DATEDIFF("h", B, C))
FROM TBL
Comments