-1
Good morning!
I’m having trouble making one CASE WHEN
of a named expression. I have a SELECT
in which one of the parameters has a named expression.
Example:
ROUND(NFI.NOTAFISCALITEM_VALORMARGEMGERENCIAL, 2))MARGEM
I want to make a check so that this expression does not return values NULL
. I tried to do so:
CASE WHEN (ROUND(NFI.NOTAFISCALITEM_VALORMARGEMGERENCIAL, 2)MARGEM) <> NULL THEN MARGEM ELSE 0 END
But that way I get a mistake saying the following:
SQL Error [102] [S0001]: Incorrect syntax near 'MARGEM'.
Can someone help me?
Assuming that what you posted is on the SELECT List or in the WHERE clause see what the manual says: "It is not permissible to refer to a column alias in a WHERE clause, because the column value Might not yet be determined when the WHERE clause is executed.". However if you just want 0 to appear when the field is NULL use the COALESCE function:
COALESCE(ROUND(NFI.NOTAFISCALITEM_VALORMARGEMGERENCIAL, 2), 0) AS MARGEM
– anonimo
It worked here, thank you very much! puts what you said as an answer for me to give the Check
– Marcos Paulo S. Rezende