'Sql case in case

i have this select:

current_date - min(case when psi.status = 'OPEN' and psi.due_date < current_date then psi.due_date end) as has_overdue_days

Return has_overdue_days its okay, but other rows are blanks in result, how to make case in case that if return blank shows '0'



Solution 1:[1]

you can use coalesce(<expr/your sql>, 0). It chooses the first non-null value from the expression list, have a 0 at the end will return 0 when blank

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tnavidi