⌘BABAKOV.NET Let's code!
100% [dark] [ru]

What to do if the query result is NULL, but it should be 0.

The following problem arose, in the case of the absence of data in the table, the result of the maximum value query in the field will output a value of null, of course, you can handle the result in the program, but it is significantly easier to assign this functionality to a script.

It is done as follows:

SELECT     (CASE WHEN MAX(ID) IS NULL THEN \'0\' ELSE MAX(ID) + 1 END) AS Expr1
FROM         MyTable


Now, if the selection is empty, i.e. null, then the result of the query will be passed as 0.

Comments (0)

No comments yet.

Leave a comment
Comment
Images (up to 5 MB)
Your comment will appear after moderation.