mercredi 23 décembre 2015

issue with CASE combined with an OR

SELECT  
    Siren,
    CASE    WHEN Code_Juridique LIKE 'M%' AND Enseigne IS NOT NULL AND Enseigne <> '' --ok
                THEN 'Enseigne : ' + Enseigne
            WHEN (Sigle IS NULL OR Sigle ='')
                AND (Enseigne IS NULL OR Enseigne ='')
                THEN '' -- ok
            WHEN
                 (Sigle IS NOT NULL OR Sigle <> '' ) THEN 'Sigle : ' + Sigle
            ELSE 'Sigle / Enseigne : ' + Sigle + ' / ' + Enseigne
        END as SigleEnseigne1,
        Sigle,
        Enseigne,
        Code_Juridique
        FROM    #JohnJack

The code is straightforward.

Issue lies with the third when as you can see below

enter image description here

I should have have nothing on my 4th and 5th line, yet it is giving me Sigle :

I tweaked my query , the issue lies with the OR as when I put an AND, it is giving me other results , no the one I'm expecting though...

Why?

Thanks for your insights

Aucun commentaire:

Enregistrer un commentaire