[Solved] Conditional field value SQL (CASE)

Creating and using forms
Post Reply
gkick
Posts: 324
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

[Solved] Conditional field value SQL (CASE)

Post 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
Last edited by gkick on Sat Aug 08, 2020 2:59 am, edited 1 time in total.
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Conditional field value SQL (CASE)

Post 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"
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
gkick
Posts: 324
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

Re: Conditional field value SQL (CASE)

Post by gkick »

@FJCC :crazy: Thanks, am going blind, so obvious!
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
Post Reply