I have the following CASE statement that returns the Closure Date
column and want to subtract the Created On
from the Closure Date
column to get the number of days difference. I can do this with DATEDIFF
but unsure how to make it it's own column using the existing CASE argument. I've tried a second CASE statement, even using a subquery, to no avail.
SELECT
createdon [Created On],
modifiedon [Modified On],
timestamp [Time Stamp],
CASE
WHEN DATEDIFF(minute,0, [Created On]) = DATEDIFF(minute,0,[Modified On]) THEN [Modified On]
ELSE [Time Stamp]
END AS 'Closure Date',
FROM
Table;
Current results:
Created On | Closure Date |
---|---|
7/14/23 21:23 | 7/14/23 13:45 |
7/14/23 21:12 | 7/14/23 12:45 |
7/14/23 21:11 | 7/14/23 12:49 |
What I am looking for:
Created On | Closure Date | Days |
---|---|---|
7/13/23 21:27 | 7/14/23 21:48 | 1.014618 |
7/14/23 9:24 | 7/14/23 21:45 | 0.514421 |
7/14/23 13:53 | 7/14/23 21:45 | 0.327616 |