Bina
Bina

Reputation: 3

Case statement to ISNULL

I am very new to T-SQL and am looking to simplify this query using isnull.

case 
when datediff(d, appdate, disdate) IS NOT NULL THEN datediff(d, appdate, disdate) 
ELSE 
    Case 
        when appdate is null THEN datediff(d,update,getdate())
        when disdate IS NULL THEN datediff(d,appdate,getdate())
    END
END

Upvotes: 0

Views: 115

Answers (1)

Zohar Peled
Zohar Peled

Reputation: 82474

Not much of a simplification but this should do the same thing:

ISNULL(datediff(d, appdate, disdate) , 
    CASE WHEN appdate IS NULL THEN datediff(d,update,getdate())
         WHEN disdate IS NULL THEN datediff(d,appdate,getdate()) END
) 

Upvotes: 1

Related Questions