Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
A database challenge
Message
From
28/02/2008 06:05:21
Walter Meester
HoogkarspelNetherlands
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01295541
Message ID:
01297308
Views:
29
>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.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform