Subject Re: [firebird-support] case - when syntax
Author Markus Ostenried
On Sun, Jul 27, 2008 at 17:57, Maurizio <mauriz_po@...> wrote:
> hi ,
> in a select statement i use :
>
> sum(case m.dmtipo when 'NC' then D.dttotrig else 0 end) AS
> "Valore 1 ",
> sum(case m.dmtipo when 'FI' then D.dttotrig else 0 end) AS
> "Valore 2 "
>
> and it does what i want ,
> just i don't know how to add an 'OR' clause : something like
> ...if dmtipo is 'FI' OR 'FD' sum D.dttotrig else 0 end) AS "Valore
> 2 " ...

Hi,

you can add another "when" clause:
sum(case m.dmtipo when 'FI' then D.dttotrig when 'FD' then
D.dttotrig else 0 end) AS "Valore 2 "

you can read about it in the file
\Firebird_2_1\doc\sql.extensions\README.case.txt
which show these two examples:

A) (simple)
SELECT
o.ID,
o.Description,
CASE o.Status
WHEN 1 THEN 'confirmed'
WHEN 2 THEN 'in production'
WHEN 3 THEN 'ready'
WHEN 4 THEN 'shipped'
ELSE 'unknown status ''' || o.Status || ''''
END
FROM
Orders o

B) (searched)
SELECT
o.ID,
o.Description,
CASE
WHEN (o.Status IS NULL) THEN 'new'
WHEN (o.Status = 1) THEN 'confirmed'
WHEN (o.Status = 3) THEN 'in production'
WHEN (o.Status = 4) THEN 'ready'
WHEN (o.Status = 5) THEN 'shipped'
ELSE 'unknown status ''' || o.Status || ''''
END
FROM
Orders o

HTH,
Markus