Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
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
ACE Emeritus
ACE Emeritus

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
ACE Emeritus
ACE Emeritus

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
20 - Arcturus
20 - Arcturus

@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 restart. Order shall return.
Please Subscribe to my youTube channel.
Labels