Bonjour,

je cherche la manière de tester si un record se trouve dans des tables différentes:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
    select 
    ...
    case 
        when (exists(select null from TMP_MATCH_A ma, T_CABLO_CUSTOMER_CONTRAT ccc where ma.CCC_ID = ccc.ID)) then 'A'
        when (exists(select null from TMP_MATCH_B mb, T_CABLO_CUSTOMER_CONTRAT ccc where mb.CCC_ID = ccc.ID)) then 'B'
        when (exists(select null from TMP_MATCH_C mc, T_CABLO_CUSTOMER_CONTRAT ccc where mc.CCC_ID = ccc.ID)) then 'C'
        when (exists(select null from TMP_MATCH_D md, T_CABLO_CUSTOMER_CONTRAT ccc where md.CCC_ID = ccc.ID)) then 'D'
        else 'NC'
    end "Type SAP"
    from
    ...
    where
    ...
Pour faire simple, je voudrais que mon champs "Type SAP" m'indique 'A' si le record courant est dans la table TMP_MATCH_A, 'B' si il est dans la table TMP_MATCH_B, etc... Or avec ce code, le résultat de la requete donne 'A' partout dans le champs. Ce CASE se trouve dans le SELECT, alors que le gros de ma requete est dans la clause WHERE qui suit. Est-ce que c'est là mon problème?

au cas où, la requete en entier donne:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
select
    distinct(abo.AB_NUMABO) "ID",
    cc.IDCUSTCABLO "SubscriberId",
    cc.SAP_PARTNER "Partner",
    abo.AB_NOM "Nom",
    abo.AB_PRENOM "Prenom",
    term.CT_NUMDEC "Decoder",
    carte.CT_NUMDEC "Smartcard",
    abo.AB_ADRESSE||' '||abo.AB_NUMERO_ADR||' '||abo.AB_BOITE_ADR||' '||abo.AB_CODPOS||' '||abo.AB_COMMUNE "Adresse",
    rue.IDRUE_VOO "code rue ",
    carte.CT_ABOBETV "Flag abo",
    deco.FLAGCABLE "Flag Dec",
    decode(bitand(B.bitmap2,1048576),0,0,1) "Flag 52",
    'NOMATCH' "Status",
    1 "Qte",
    ccc.ID "CCC Id",
    '0' "Flag EOS",
    decode(tmp.BETV_ID,null,0,1) "Flag fichier",
    case 
        when (exists(select null from TMP_MATCH_A ma, T_CABLO_CUSTOMER_CONTRAT ccc where ma.CCC_ID = ccc.ID)) then 'A'
        when (exists(select null from TMP_MATCH_B mb, T_CABLO_CUSTOMER_CONTRAT ccc where mb.CCC_ID = ccc.ID)) then 'B'
        when (exists(select null from TMP_MATCH_C mc, T_CABLO_CUSTOMER_CONTRAT ccc where mc.CCC_ID = ccc.ID)) then 'C'
        when (exists(select null from TMP_MATCH_D md, T_CABLO_CUSTOMER_CONTRAT ccc where md.CCC_ID = ccc.ID)) then 'D'
        else 'NC'
    end "Type SAP"
from
AB_ABONN abo,
T_MAPPING_RUES rue,
CT_CONTRT carte ,
CT_CONTRT term ,
T_LIEN_CONTRATS lien ,
T_CABLO_CUSTOMER_CONTRAT ccc,
T_CABLO_CUSTOMER cc,
v_ff_deco deco,
T_SMARTCARD_DEF A, 
T_SMARTCARD_OBJ B,
T_MATCHING_TMP tmp
where
    abo.AB_NUMABO = carte.CT_NUMABO
and cc.ID=ccc.REF_CABLO_CUSTOMER_ID
and carte.CT_ID = lien.CT_ID_FATHER
and lien.CT_ID = term.CT_ID
and rue.IDRUE_BETV(+)= abo.AB_IDRUE
and carte.CT_ETAT in (2,3,5,6)
and carte.CT_ID = ccc.REF_CONTRAT_ID
and ccc.ETAT = 8
and ccc.REF_SMARTCARD_ID is not null
and ccc.REF_DECODER_ID is not null
and A.ID = ccc.REF_SMARTCARD_ID 
and A.IDSC = B.ID
and deco.IDDECO=term.CT_NUMDEC 
and carte.CT_ABOBETV = 1
and cc.OPERATORID in (2,3,4,5)
and tmp.BETV_ID (+)= abo.AB_NUMABO
and not exists (
select null from T_CABLO_CUSTOMER_CONTRAT Z 
where Z.REF_CONTRAT_ID=ccc.REF_CONTRAT_ID and Z.ID<ccc.ID and Z.EVT='EOS'
)