views:

543

answers:

3

I have written a DB2 query to do the following:

  • Create a temp table
  • Select from a monster query / insert into the temp table
  • Select from the temp table / delete from old table
  • Select from the temp table / insert into a different table

In MSSQL, I am allowed to run the commands one after another as one long query. Failing that, I can delimit them with 'GO' commands. When I attempt this in DB2, I get the error:

DB2CLI.DLL: ERROR [42601] [IBM][CLI Driver][DB2] SQL0199N The use of the reserved
word "GO" following "" is not valid. Expected tokens may include: "". 
SQLSTATE=42601

What can I use to delimit these instructions without the temp table going out of scope?

+1  A: 

I would try wrapping what you are looking to do in BEGIN and END to set the scope.

GO is not a SQL command, it's not even a TSQL command. It is an instruction for the parser. I don't know DB2, but I would imagine that GO is not neccessary.

From Devx.com Tips

Although GO is not a T-SQL statement, it is often used in T-SQL code and unless you know what it is it can be a mystery. So what is its purpose? Well, it causes all statements from the beginning of the script or the last GO statement (whichever is closer) to be compiled into one execution plan and sent to the server independent of any other batches.

Matthew Vines
+3  A: 

GO is something that is used in MSSQL Studio, I have my own app for running upates into live and use "GO" to break the statements apart.

Does DB2 support the semi-colon (;)? This is a standard delimiter in many SQL implementations.

ck
That's a bit complicated in DB2. Normally, the default delimiter is the semicolon, however, in the bodies of stored procedures et al, the delimiter is always a semicolon while the delimiter used _after_ the CREATE PROCUEDURE/whatever command must be something else. You can override this delimiter in the environment you're calling DB2 from. Traditionally, \\ is used as "outer delimiter" but you can use any other string.
DrJokepu
+1  A: 

have you tried using just a semi-colon instead of "GO"?

This link suggests that the semi-colon should work for DB2 - http://www.scribd.com/doc/16640/IBM-DB2

Scott Ivey