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 > DB2 dynamic sql query inside of the sql script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-06-04, 11:30
Brownie Brownie is offline
Registered User
 
Join Date: Aug 2004
Posts: 2
Angry DB2 dynamic sql query inside of the sql script

I work on db2 v 8.01 for AIX.
Is it possible to write dynamic sql query inside the script like in store procedure?
I would like to be able to define variables and execute dynamic queries from within the script - something like:
DECLARE stmt VARCHAR(1000);
DECLARE table_name VARCHAR(50);
SET table_name = 'DEPT_'||deptNumber||'_T';
SET stmt = 'DROP TABLE '||table_name;
PREPARE s1 FROM stmt;
EXECUTE s1;


I can do that from within the store procedure but not in the script.

Please help
Reply With Quote
  #2 (permalink)  
Old 08-06-04, 11:59
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Why not just write a shell script?
Reply With Quote
  #3 (permalink)  
Old 08-10-04, 10:16
dmmac dmmac is offline
Registered User
 
Join Date: Aug 2003
Location: Massachusetts, USA
Posts: 106
A suggestion....

Create a script with this:
SELECT 'DROP TABLE ' || name FROM sysibm.systables
WHERE name LIKE 'DEPT_%_T'
@

Execute
db2 -td@ -f script > drop.$$

Then
db2 -t -f drop.$$
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