Subject Re: [ib-support] DECODE
Author lester@lsces.co.uk
> When I sarted to learn sql, I was reading an oracle book.
> The first 80 page is about base sql.
> But there is an sql statement this book.
> And it is very interesting.
>
> SELECT NAME, FIRSTNAME, LASTNAME,
> DECODE(JOB, 'SALES','1','ACCOUNT','2','MANAGER','3') FROM TABLE1;
>
> Fetched records:
>
> John, AAa, AAA, AAAAAAAA, 1
> Michale, bbb, ccc, ccccccccccc, 3
> Alice, gggg, aaaaaaa, gggggggg, 2
>
> I understand, decode like a case clause.
>
> Case Decode Of
> Sales : Result:=1;
> Account : Result:=2;
> Manager :Result:=3;
> End;
>
>
> Can I do it with interbase.

Rather than building this sort of thing into the SELECT, I
prefer to use the 'relational' way of doing it.

Replace the DECODE with

( SELECT NUMBER FROM JOBTABLE WHERE JOB = TABLE1.JOB )

This is normally used the other way round, so that you have
a job number in TABLE1, and have all the information for
each JOB in a separate JOBTABLE.

--
Lester Caine
-----------------------------
L.S.Caine Electronic Services