Walter Meester
HoogkarspelPays-Bas
Information générale
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
>Doing a CASE WHEN in a where clause smells like amatuerism.
First of all, "Smells"....
>Ouch....you might want to re-think that one.
>If that indeed is true, then we have an awful lot of SQL authors, MVPs, and the good Lord J.C. himself (Celko) who would fall into that (all have printed queries that use it....it was about 6 years ago when I starting seeing a lot of it in print)
The WHERE clause takes a boolean expression... there should not be anything that cannot be expressed with AND and OR. Sometimes it might be easier or neccesarry to have a CASE WHEN in an argument of the expression e.g (CASE WHEN x THEN Field1 WHEN y FIELD2 ELSE Field3 END > aValue) but never *be* the boolean expression (as you did). On the average one should avoid them. . The reasoning behindit is:
- Any Boolean logic expression can be descibed with AND and OR
- Developers are used to think in terms of AND and OR.
- CASE WHEN expressions are not optimizable.
Please give me an example of those SQL authors who do advocate using them in WHERE clauses. Also I don't have an high opinion per se on any MVP in this regards. MVP does not stand for any level of quality.
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement