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!
Solved! Go to Solution.
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
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
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