I ran into a problem trying to understand DB2 sql (note, I come from MS SQL Server): P.
Here is the scenario, I have 2 tables that have identifiers and other data, the second has a lot of other information corresponding to each ID.
ID Info for ID _______ ____> _______ | | / | | | T1 |<---------> | T2 | |_____| \____> |_____|
Coming from SQL Server, I use scripts like:
Declare @ID int Declare @ID1 int select @ID=ID from T1 where col1 = @ID1 select * from T2 where ID = @ID
All this works great and gives me ID ID1, which can be used to get all the identifier information from T2.
Unfortunately, in DB2 this explodes right on my face, I am afraid that if I run this request again, it will forever renounce me: (.
I did some research and wrote this (I was even stuck in a variable declaration).
--#SET TERMINATOR @ BEGIN ATOMIC DECLARE UID char(30); END @
For others, it worked fine, but I get the following error:
BEGIN ATOMIC DECLARE UID char(30); END ILLEGAL USE OF KEYWORD ATOMIC. TOKEN WAS EXPECTED. SQLCODE=-199, SQLSTATE=42601, DRIVER=3.63.108
Additional Information:
IBM DB2 for z / OS V9.1 IBM Data Studio V3.1.1.0
[EDIT: using DECLARE] Another thing I tried that didn't work:
CREATE VARIABLE UID CHAR(30) DEFAULT 'USERID'; select * from testdb2.T1 A WHERE A.UID=v_UID;
TIA, Abhinav
May 13, 2016 Patch (Friday the 13th)
Creating a stored procedure is the only way to eliminate it: (