QUERY containing different and or

3

I need to do a query where the status of that person can be A = Active, I = Inactive and B = Locked but can also be null, my query is already returning when it is A, B or I but when it is null no returns nothing.

select COD_IDENT_PESSO,
       TXT_NOMEX_PESSO,
       TXT_APELI_PESSO,
       case FLG_SEXOX_PESSO when 'F' then 'Feminino' when 'M' then 'Masculino' end as FLG_SEXOX_PESSO,
       if(DAT_NASCI_PESSO is null, '', date_format(DAT_NASCI_PESSO, '%d/%m/%Y')) as DAT_NASCI_PESSO,
       case FLG_STATU_PESSO when 'A' then 'Ativo' when 'I' then 'Inativo' when 'B' then 'Bloqueado' end as FLG_STATU_PESSO,
       if(DAT_ADMIS_PESSO is null, '', date_format(DAT_ADMIS_PESSO, '%d/%m/%Y')) as DAT_ADMIS_PESSO
       from DB_EGLISE.tbl_PESSOAS
       where COD_IDENT_IGREJ = 'ibar'
       and FLG_STATU_PESSO <> 'A' or //PROBLEMA ESTA AQUI
       FLG_STATU_PESSO = null //E AQUI
       order by TXT_NOMEX_PESSO

In my query I need to return anything that is different from A or that is null.

    
asked by anonymous 24.03.2016 / 12:09

1 answer

4

You have to use IS NULL when you want the fetch to return only NULL values or IS NOT NULL when you want to only return values different from NULL .

change the rows.

  

and FLG_STATU_PESSO < > 'A' or // PROBLEM IS HERE

     

FLG_STATU_PESSO = null // AND HERE

To

  

and (FLG_STATU_PESSO 'A' or FLG_STATU_PESSO is null)

select COD_IDENT_PESSO,
       TXT_NOMEX_PESSO,
       TXT_APELI_PESSO,
       case FLG_SEXOX_PESSO when 'F' then 'Feminino' when 'M' then 'Masculino' end as FLG_SEXOX_PESSO,

       if(DAT_NASCI_PESSO is null, '', date_format(DAT_NASCI_PESSO, '%d/%m/%Y')) as DAT_NASCI_PESSO,

       case FLG_STATU_PESSO when 'A' then 'Ativo' when 'I' then 'Inativo' when 'B' then 'Bloqueado' end as FLG_STATU_PESSO,
       if(DAT_ADMIS_PESSO is null, '', date_format(DAT_ADMIS_PESSO, '%d/%m/%Y')) as DAT_ADMIS_PESSO
       from DB_EGLISE.tbl_PESSOAS

       where COD_IDENT_IGREJ = 'ibar'
       and (FLG_STATU_PESSO <> 'A' or FLG_STATU_PESSO is null)
       order by TXT_NOMEX_PESSO
    
24.03.2016 / 12:26