Compare null field

Asked

Viewed 28 times

-1

Good afternoon guys, all right? I am putting together a financial report where I wish to create a field that returns me whether that amount has been paid or not. The query checks the date of the drop if it is filled it will show in the field that the amount was paid and if it is empty it will show that it was not paid. But I’m having difficulties in this comparison. They could show me the error in the query: SELECT NUFIN,AD_DTVENCALTER,DHBAIXA CASE DHBAIXA WHEN dhbaixa IS NULL THEN 'Não' WHEN dhbaixa NOT NULL THEN 'sim' END AS situação FROM TGFFIN

1 answer

1


I believe only one comma is missing before CASE and I’m not sure either, but in case you check how NULL nor need to put in the CASE column name, you’ve already added in WHEN (because of the IS NULL)

And something that’s not even a problem but would make it easier to use the ELSE instead of another WHEN when the condition is "contrary" to another

This must be what you want (communicate to me if something fails, I could not test):

SELECT NUFIN, AD_DTVENCALTER, DHBAIXA,
  CASE
      WHEN dhbaixa IS NULL THEN 'Não'
      ELSE 'sim' 
   END AS situação
FROM TGFFIN

I’m not sure because I’ve rarely used accents in names, but if I fail to AS situação trade it in for:

END AS "situação"
  • Thank you so much for the help, friend. Gave straight. I’m starting now on this walk and I’m suffering haha

  • @Pablodossantosneves please mark the answer as correct, since it solved your problem. Thank you!

  • Ready @guilhermeNascimento. Sorry, I’m learning to use the forum yet. I have no experience with this type of community.

  • No problem, thank you!

Browser other questions tagged

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