SQL decode function applied DATES

3

I'm having a doubt, I need to do a select where I need to show if a customer's registry is active or not, in the database it is treated as follows, there is an exit date field if the field is blank the registration is active now if the registration is completed I need to show that it is inactive. To do this SQL how can I use the DECODE function.

    
asked by anonymous 13.01.2017 / 18:05

2 answers

3

Assuming a DATE field, two solutions

1) DECODE(DATA_SAIDA,NULL,'ATIVO','INATIVO') STATUS

2) (CASE WHEN DATA_SAIDA IS NULL THEN 'ATIVO' ELSE 'INATIVO' END) STATUS
    
13.01.2017 / 18:42
1

The motta solution works perfectly, but you can also use the NVL2 function. The code becomes more readable.

NVL2( string1, value_if_not_null, value_if_null )

See the link: link

    
21.01.2017 / 19:45