Do you use Alteryx in a language other than English? If so, we want to hear from you! Please help us improve the international experience of our products by participating in this 5 minute survey.

We are updating the requirements for Community registration. As of 7/21/21 all users will be required to register a phone number with their My Alteryx accounts. If you have already registered, you will be prompted on your next login to add your phone number.

Alteryx Designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.
SOLVED

IN-DB Formula Tool (IF vs Case)

paultno
8 - Asteroid

I keep running into Syntax errors when using the IN-DB Formula tool and was wondering if there are any examples out there?  I have read that some users are using CASE instead of IF but could use some advice.  I understand that we are supposed to be using Quotations instead of Brackets for the DB tools.  Here is my example

 

if "VAR1" = "VAR2" then "VAR2"

else if "VAR1" = "VAR3" then "VAR3"

else "VAR4"

 

Thank you!

4 REPLIES 4
BenMoss
17 - Castor
17 - Castor

The syntax is entirely dependent on the type of DB you are connecting to and this also determains what functions are available to you.

 

Could you please confirm what type of DB you are connecting too?

 

Ben

BenMoss
17 - Castor
17 - Castor

The following CASE statement should work in an SQL DB, based on this post: https://community.alteryx.com/t5/Data-Preparation-Blending/In-DB-Nested-IF-Statement/m-p/94083#M1841...

 

CASE
WHEN "VAR1" = "VAR2" THEN "VAR2"
WHEN "VAR1" = "VAR3" THEN "VAR3"
ELSE "VAR4"
END

If you want to compare to text then the text should be contained within single qoutes.

 

Ben

paultno
8 - Asteroid

Hi Ben,

 

Thanks for your help.  It really got me on the right track to figure it out.  However, it turns out that you have to place single quotations for anything that isn't a variable.  In our case, we got error messages when leaving everything in double quotations.  Please see the corrected example below.   

 

CASE
WHEN "VAR1" = 'Mike' THEN 'Mike'
WHEN "VAR1" = 'Linda' THEN 'Linda'
ELSE 'Curt'
END

 Paul

MarqueeCrew
19 - Altair
19 - Altair

@BenMoss,

 

I'll give you a star!  I think that you earned it (at least the assist, if not the solve).

 

Cheers,

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and reboot. Order shall return.
Please Subscribe to my youTube channel.
Labels