QUERY containing different and or

Asked

Viewed 115 times

3

I need to do a query where that person’s status can be A = Active, I = Inactive and B = Blocked but it can also be null, my query is already returning when it is A, B or I but when it is null it 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 you to return anything other than A or null.

  • 2

    Tries with AND (FLG_STATU_PESSO IS NULL OR FLG_STATU_PESSO <> 'A')

1 answer

4


You have to use the IS NULL when you want your search to return only values NULL or IS NOT NULL when you want only return different values of NULL.

changes the lines.

and FLG_STATU_PESSO <> 'A' or //PROBLEM THIS ONE

FLG_STATU_PESSO = null//E 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.