Join the Alteryx Community’s Maveryx Summer Cup event! Compete, network with others, and earn your gold through a series of challenges from July 24th to August 11th. Learn more about the event here.

Alteryx Designer Desktop Discussions

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

Help with SQL formula

MaryCann
8 - Asteroid

Hello everyone,

I'm trying to get the below SQL formula to work in the Alteryx Formula tool - 

IF [Disposition Comment] CONTAINS "%medication%"
OR [Disposition Comment] CONTAINS "%meds%"
OR [Disposition Comment] CONTAINS "%Dr. Gould%"
OR [Disposition Comment] CONTAINS "%Dr. Zimmerman%"
OR [Disposition Comment] CONTAINS "%Psych%"
OR [Disposition Comment] CONTAINS "%doctor%"
OR [Disposition Comment] CONTAINS "%Lindsey G. PA%"
OR [Disposition Comment] CONTAINS "%med refill%"
AND [Program Name] CONTAINS "MH%"
THEN "Psych" ELSE "Not Psych" ENDIF

 

But I keep getting this "Malformed If Statement"

What am I doing wrong???

 

5 REPLIES 5
apathetichell
19 - Altair

the syntax for the contains function is contains([field],"X")

ChrisTX
15 - Aurora

Your syntax is off a little.  Check out the examples for the Contains function:

 

https://help.alteryx.com/current/en/designer/functions/string-functions.html##

 

And delete the % characters inside each double quote.

 

You may also need some parenthesis around your OR and AND clauses.

 

Chris

 

MaryCann
8 - Asteroid

Okay, these suggestions helped - Thank you!  Updated to:

 

IIF(Contains([Disposition Comment], 'medication') OR
Contains([Disposition Comment],'meds') OR
Contains([Disposition Comment], 'Dr. Gould') OR
Contains([Disposition Comment], 'Dr. Zimmerman') OR
Contains([Disposition Comment], 'Psych') OR
Contains([Disposition Comment], 'doctor') OR
Contains([Disposition Comment], 'Lindsey G. PA') OR
Contains([Disposition Comment], 'med refill') AND
Contains([Program Name], 'MH')
THEN "Psych" ELSE "Not Psych" ENDIF

 

At the THEN I'm now getting a "Malformed If Statement"  error.  So, better... 

 

alexnajm
17 - Castor
17 - Castor

You changed IF to IIF at the beginning - I would change it back. In addition, it looks like you may have an extra open parentheses at the beginning!

MaryCann
8 - Asteroid

That worked!!!!!!!!!!  THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU!

Labels