Question on Converting Query Syntax from SQL to DB2

Jim Aloye

Question on Converting Query Syntax from SQL to DB2

I am just getting into DB2 and have been slowly converting numerous queries from MSSQL to DB2. However I hit a snag in that process and am hoping for some advise.

It seems that certain things like the sql code required to declare variables and temporary tables are significantly different in DB2 in comparison to MSSQL.

The code below works perfectly in a MSSQL query when executed from the SQL Management console.

DECLARE @LastStartDate DATETIME

SET @LastStartDate = (SELECT LSTARTTIME FROM CRIMINAL.ALOTEST09 WHERE JOBNAME = 'Basic_Data_Load_CPS')

SELECT @LastStartDate as [The Date We Need To Use]

However, when I use this same code, when connected to the DB2 version of the database, it errors out miserably.

I tried re-formatting as follows but stil get errors.

BEGIN ATOMIC

DECLARE @LastStartDate TIMESTAMP

SET @LastStartDate = (SELECT LSTARTTIME FROM CRIMINAL.ALOTEST09 WHERE JOBNAME = 'Basic_Data_Load_CPS')

SELECT @LastStartDate as [The Date We Need To Use]

END

Clearly, I am missing something, and am hoping to find that missing information here.

I basically need to write the same thing for DB2 so I can execute it from a DB Artisan SQL Console when connected to a DB2 database.

I checked alot of forums but can't seem to find syntax or formatting info that actually allows my sql statement to successfully execute without errror.

Any help or advice would be appreciated

Jim Aloye

RE: Question on Converting Query Syntax from SQL to DB2
(in response to Jim Aloye)

attn admin: this post can be deleted also. I put it in the wrong section. I already recieved a response on this when I put it in the db2 L section.