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 > Parameter Marker in Dyanmic SQL??

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-16-07, 09:09
mahi123 mahi123 is offline
Registered User
 
Join Date: Dec 2005
Posts: 8
Parameter Marker in Dyanmic SQL??

Hi,

I have a Static SQL and wish to write as a Dynamic SQL since the FROM Clause and WHERE Clause may change depending on some situations

Here is the Static SQL:

SELECT COUNT(*)
INTO :WS-COUNT
FROM EC181
WHERE PRCS_STTS_NM = 'NEW'

I understand that Host Variables cannot be used in Dynamic SQL and that Parameter Marker may be used in its place.
However, I have not seen any examples of how a Paramerter Marker can be used. Also, if I use Parameter Marker in place of WS-COUNT, how can I capture the count value in any variable? The count value captured needs to be passed to another program.

Please let me know how to execute the above SQL as a Dynamic SQL.

Thanks!!
Reply With Quote
  #2 (permalink)  
Old 04-16-07, 11:12
guyprzytula guyprzytula is offline
Registered User
 
Join Date: Jun 2006
Posts: 471
Host Variables cannot be used in Dynamic SQL ????
the statement is a character string/variable
if a variable (with predicate where value) is placed in this string, this will be taken in account when prep is executed...
__________________
Best Regards, Guy Przytula
DB2 UDB LUW certified V6/7/8
Reply With Quote
  #3 (permalink)  
Old 04-16-07, 13:53
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
You cannot use the SELECT ... INTO ... with dynamic SQL, you must use a cursor instead.

An Example for PL/1:

DCL HOST CHAR(54);
HOST = 'SELECT COUNT(*) FROM EC181 WHERE PRCS_STTS_NM = ''NEW'' ';

EXEC SQL DECLARE CUR1 FOR STMT;
EXEC SQL PREPARE STMT FROM :HOST ;
EXEC SQL OPEN CUR1 ;
EXEC SQL FETCH CUR1 INTO :WS_COUNT ;

Parameter marker may be used in the WHERE-clause:
DCL HOST CHAR(54);
DCL PARM1 CHAR(3);
EXEC SQL DECLARE CUR1 FOR STMT;
HOST = 'SELECT COUNT(*) FROM EC181 WHERE PRCS_STTS_NM = ? ';
PARM1 = 'NEW' ;
EXEC SQL PREPARE STMT FROM :HOST;
EXEC SQL OPEN CUR1 USING :PARM1 ;
EXEC SQL FETCH CUR1 INTO :WS_COUNT ;
Reply With Quote
  #4 (permalink)  
Old 04-21-07, 05:00
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Parameter markers (i.e. ?) can be used with dynamic SQL. Maybe you are talking about host variables here?
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
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