If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Compound SQL Statement failing in Command Editor

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-19-08, 18:13
TROY1906 TROY1906 is offline
Registered User
 
Join Date: Nov 2008
Posts: 1
Compound SQL Statement failing in Command Editor

Hey Everyone!

I'm urgently trying to submit a statement using CE and it is failing. The log is attached:

------------------------------ Commands Entered ------------------------------
BEGIN

DECLARE csr1 CURSOR FOR
select a.orders_id, 'FEDEX Shipment Confirmation for SKU ' CONCAT a.PARTNUM CONCAT ' sent to Address NickName "' CONCAT b.NICKNAME CONCAT '" is ' CONCAT a.description
from wcuser.orderitems a inner join wcuser.address b on a.address_id = b.address_id
where a.description is not null with ur;

DECLARE myCOUNT INTEGER;
SET myCOUNT = 21501;

OPEN csr1;
FETCH FIRST csr1 INTO :ORDERS_ID, :FEDEXCOMMENT;
while(SQLCODE==0) DO
INSERT INTO WCUSER.ORCOMMENT
(ORCOMMENT_ID, ORDERS_ID, COMMENTS)
VALUES (myCount, :ORDERS_ID, :FEDEXCOMMENT) ;
SET myCOUNT = myCOUNT + 1;
FETCH NEXT FROM csr1 INTO :ORDERS_ID, :FEDEXCOMMENT;
END WHILE;
CLOSE csr1;
END@
------------------------------------------------------------------------------
BEGIN DECLARE csr1 CURSOR FOR select a.orders_id, 'FEDEX Shipment Confirmation for SKU ' CONCAT a.PARTNUM CONCAT ' sent to Address NickName "' CONCAT b.NICKNAME CONCAT '" is ' CONCAT a.description from wcuser.orderitems a inner join wcuser.address b on a.address_id = b.address_id where a.description is not null with ur; DECLARE myCOUNT INTEGER; SET myCOUNT = 21501; OPEN csr1; FETCH FIRST csr1 INTO :ORDERS_ID, :FEDEXCOMMENT; while(SQLCODE==0) DO INSERT INTO WCUSER.ORCOMMENT (ORCOMMENT_ID, ORDERS_ID, COMMENTS) VALUES (myCount, :ORDERS_ID, :FEDEXCOMMENT) ; SET myCOUNT = myCOUNT + 1; FETCH NEXT FROM csr1 INTO :ORDERS_ID, :FEDEXCOMMENT; END WHILE; CLOSE csr1; END
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "BEGIN DECLARE csr1 CURSOR FOR" was found
following "BEGIN-OF-STATEMENT". Expected tokens may include: "<space>".
SQLSTATE=42601

SQL0104N An unexpected token "BEGIN DECLARE csr1 CURSOR FOR" was found following "BEGIN-OF-STATEMENT". Expected tokens may include: "<space> ".

Explanation:

A syntax error in the SQL statement or the input command string
for the SYSPROC.ADMIN_CMD procedure was detected at the specified
token following the text "<text>". The "<text>" field indicates
the 20 characters of the SQL statement or the input command
string for the SYSPROC.ADMIN_CMD procedure that preceded the
token that is not valid.

As an aid, a partial list of valid tokens is provided in the
SQLERRM field of the SQLCA as "<token-list>". This list assumes
the statement is correct to that point.

The statement cannot be processed.

User Response:

Examine and correct the statement in the area of the specified
token.

sqlcode : -104

sqlstate : 42601
Reply With Quote
  #2 (permalink)  
Old 11-19-08, 20:50
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
There are so many things wrong I don't know where to start...

- BEGIN ATOMIC...
- cursor declarations come after variable declarations
- FETCH FIRST? FETCH NEXT?
- host variables are declared where exactly?
- logical expression incorrect

May be it's time to RTFM...

Besides, I think you might be able to achieve your goal with a single INSERT statement...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On