Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

HELP converting SQL Query to Alteryx

elsa2020
5 - Atom

Help I am a new student learning Alteryx and  I am trying to convert the following SQL Query to Alteryx: 

Any insight and assistance will be greatly appreciated. Thank you.

 

CASE WHEN AFFECTED_FAM_MEMBER = 'EMPLOYEE' THEN DATEADD(DAY, 9, COVID_ENTRY_DATE) ,
WHEN AFFECTED_FAM_MEMBER = 'FAMILY' THEN DATEADD(DAY, 7, COVID_ENTRY_DATE)
ELSE 'UNKNOWN'
END AS 'Work_Return_Date'
FROM [dbo].[JULY_COVID DATA]

3 REPLIES 3
ehughes
9 - Comet

Hi @elsa2020,

I'm not a SQL expert but it looks like you'll need an Input tool to bring in the JULY_COVID DATA from your dbo. Then you'll want a Formula tool where you Add a Column ('Work_Return_Date') and a very similar formula to what you already have:

IF [AFFECTED_FAM_MEMBER]='EMPLOYEE' THEN DateTimeAdd( [COVID_ENTRY_DATE], 9, 'day')
ELSEIF [AFFECTED_FAM_MEMBER = 'FAMILY' THEN DateTimeAdd( [COVID_ENTRY_DATE], 7, 'day')
ELSE 'UNKNOWN'
ENDIF

You may need an extra step before the Formula tool (with a select tool) to check that the Date Column is reading as a date (data type). If not, then you can use the DateTime tool to convert it from a String type to a Date type.

Hope that helps!

Qiu
20 - Arcturus
20 - Arcturus

@elsa2020 
As suggested by @ehughes , Input Tool provides Data Connection.

If your query works in Database side, it should work here as well, so you can even copy the entire query and proceed from there.

Untitled1.pngUntitled2.png

kelsey_kincaid
12 - Quasar

Hi @elsa2020 ,

As others have noted, you'll want to start with getting your data into Alteryx using an Input Data tool. In the event that you opt not to copy and paste the query directly into the SQL editor per @Qiu 's suggestion and want to use a formula, you can either follow @ehughes 's suggested formula or use a SWITCH statement in the formula tool. A switch statement is very similar to a case statement, so you might be more comfortable with it.

 

Switch([AFFECTED_FAM_MEMBER],'UNKNOWN',

'EMPLOYEE',DATEADD([DAY],9,[COVID_ENTRY_DATE]),

'FAMILY',DATEADD([DAY],7,[COVID_ENTRY_DATE]))

 

As I'm sure you're gathering, there are a lot of ways to accomplish the same thing within Alteryx! Let me know if you have additional questions.

Labels