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.
SOLVED

Post SQL statement - how to execute statements in batch.

-Daniel-
6 - Meteoroid

I have an output that is writing to a database (create) and I'd like to run the following SQL post create. How should this be handled?

 

 

ALTER table Person ALTER column PersonID integer not null
GO
ALTER table Person add primary key (PersonID)

 Edit: 

When adding this statement to the Post Create SQL Statement - I receive the following error. 

Incorrect syntax near 'GO'

 

5 REPLIES 5
nick_ceneviva
11 - Bolide

Do you want to make this change before any data is entered or afterwards?  

 

When using an OLEDB output, there is a place to configure a Post Create SQL statement, and you should be able to put the query there.

-Daniel-
6 - Meteoroid

Thanks for your comment - but I actually was getting an error when I configured the Post Create SQL Statement in the output tool. I've edited my original question to include this.

nick_ceneviva
11 - Bolide

It should work if you remove the "GO".

 

Hopefully that helps!

-Daniel-
6 - Meteoroid

Unfortunately when I remove the "GO" I get a different error because I'm trying to alter a PK constraint on a nullable field, one that is also being altered in the same batch. Creating a child batch using EXEC seemed to work:

 

 

ALTER table Person ALTER column PersonID integer not null

EXEC('
ALTER table Person add primary key (PersonID)
')

 

 

Ref: https://stackoverflow.com/questions/15740997/alter-table-then-update-in-single-statement

 

adm510
11 - Bolide

Remove Go, add a semicolon at the end of each query.

 

 

ALTER table Person ALTER column PersonID integer not null;

ALTER table Person add primary key (PersonID);
Labels