decode and where clause
Date: 2000/06/19
Message-ID: <oW$0iQf2$GA.163_at_news-02.uni.net>#1/1
here is my question about decode. thanks in advance for your help and
patience.
i want to reach details of an accused person|firm details according to the
type column in accused table related with a specific file. if type in
accused table is 'CON' (consultant) or 'STA' (staff), details are taken from
accused_person_details table by type and no. if type in accused table is
'FIR' (firm) details are taken from accused_firm_details table by no. if
type is 'OTH' (other), details (name, surname) are in accused table.
SELECT accused_table.file_type,accused_table.file_number,
DECODE( accused_table.type,'FIR',accused_firm.firm_name,'CON',
accused_person_details.no||' '||accused_person_details.name||'
'||accused_person_details.surname,'STA', accused_person_details.no||'
'||accused_person_details.name||' '||accused_person_details.surname,'OTH',
accused_table.firstname||' '||accused_table.surname)
FROM accused, accused_person_details, accused_firm_details
WHERE (accused_table.file_type='IDA') and (accused.file_number=6)
and ( ( accused.type.no=hfirma.tax_number) or
( ( accused.type=accused_person_details.type) and
(accused.no=accused_person_details.no) ) );
accused table ;
file_type VARCHAR2(3) file_number NUMBER(6) .... name VARCHAR2(20) surname VARCHAR2(20) type VARCHAR2(3) no VARCHAR2(12) accused_person_details table; no VARCHAR2(12) type VARCHAR2(3) name VARCHAR2(20) surname VARCHAR2(20) accused_firm_details table; tax_number VARCHAR2(12) firm_name VARCHAR2(50)Received on Mon Jun 19 2000 - 00:00:00 CEST