Page 1 of 1

[Solved] Conditional field value SQL (CASE)

Posted: Fri Aug 07, 2020 11:16 pm
by gkick
Hi all,

Having a slight problem with a CASE statement. I need to show either the value of the acttax or tinclusive fields based on the value of the TaxRate field.

I am using the following code which produces an error and I can not figure out the message...

Code: Select all

SELECT "jobid",
        "TaxRate",
		"acttax",
		"tinclusive",
        CASE
           WHEN "TaxRate = 0 THEN "tinclusive"
           ELSE "acttax"
        END as "offset"
 FROM "ccTaxes"
Anyone spotting my mistake ? Thank you

Re: Conditional field value SQL (CASE)

Posted: Sat Aug 08, 2020 12:29 am
by FJCC
I think you have a missing a double quote after TaxRate. Try

Code: Select all

SELECT "jobid",
        "TaxRate",
      "acttax",
      "tinclusive",
        CASE
           WHEN "TaxRate" = 0 THEN "tinclusive"
           ELSE "acttax"
        END as "offset"
FROM "ccTaxes"

Re: Conditional field value SQL (CASE)

Posted: Sat Aug 08, 2020 2:59 am
by gkick
@FJCC :crazy: Thanks, am going blind, so obvious!