'How to have comparison with CASE in SQL
WHERE
CASE
WHEN @TypeFatt <> -1
THEN docAM.typCIGA = @TypeFatt
ELSE docAM.typCIGA > @TypeFatt
END
The error is
Incorrect syntax near '='
Why?
Thanks for your help
Solution 1:[1]
It's generally better to use regular AND/OR constructions instead of case expressions in the WHERE clause:
WHERE (@TypeFatt <> -1 AND docAM.typCIGA = @TypeFatt)
OR (@TypeFatt = -1 AND docAM.typCIGA > @TypeFatt)
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 |
