cancel
Showing results for 
Search instead for 
Did you mean: 

Post SQL statement - how to execute statements in batch.

SOLVED
-Daniel-
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'

 

nick_ceneviva
Alteryx Certified Partner

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-
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
Alteryx Certified Partner

It should work if you remove the "GO".

 

Hopefully that helps!

-Daniel-
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
Fireball

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);