I try to select max value from table
SELECT MAX(cid) FROM itemconfiguration;
However when table itemconfiguration is empty the MAX(cid) statements is evaluated to NULL while i need a number. How to handle this and treat NULL as 0 ?
I try to select max value from table
SELECT MAX(cid) FROM itemconfiguration;
However when table itemconfiguration is empty the MAX(cid) statements is evaluated to NULL while i need a number. How to handle this and treat NULL as 0 ?
Just use Coalesce or NVL to handle NULLs.
The following code will return 0 if MAX(cid) is NULL
SELECT COALESCE(MAX(cid), 0)
FROM itemconfiguration
Can replace a number when max return null using ISNULL ,
ISNULL(MAX(cid),0) FROM itemconfiguration;