Main page
About the use of the operator CASE
S. Moiseenko
In the help on a site the syntax
of this operator is described and examples of its use are given. However these examples
show an application of the CASE in the statement SELECT. Actually, the statement
SELECT is the place of the most often use of the operator CASE, however it is not
the only thing. We may use the CASE practically everywhere. Here I shall show some
examples of its use in the other statements of the operator SELECT.
The statement WHERE.
The statement WHERE limits a target set to those lines which satisfy to a predicate
in this statement. Let us suppose that we have such conformity between a memory
size of the personal computer and a type of used operational system (conditionally):
RAM < 64 W95
RAM >=64 и < 128 W98
RAM >= 128 W2k
If we shall want to select computers by type of OS (we shall notice, that such field
isn't in table PC) it is possible to write the following operator:
SELECT * FROM pc
WHERE CASE WHEN ram <64 THEN 'W95'
WHEN ram <128 THEN 'W98'
ELSE 'W2k' END
='W98'
Here we choose the models fit to the operational system W98. The result of the execution
of this query is given below.