Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2015
    Posts
    1

    Question Unanswered: How fill the '?' parameter in the sql query

    Hello all,

    I'm brand new in DB2. I'm trying to create some procedures but I'm failing. The problem is this: I got a table, where there's a specific SQL to be run with a parameter '?' which has to be filled:

    table name: TASKS

    ID SQL
    1 insert into students (firstName, lastName, checkId) select firstName, lastName, ? from kids where age = 18
    2 insert into students (firstName, lastName, checkId) select firstName, lastName, ? from kids where sex = 'female'
    3 insert into students (firstName, lastName, checkId) select firstName, lastName, ? from kids where grade = 'b+'



    and so on.

    The exercise is:

    1. select the ID and SQL from above table;

    2. Run the selected SQL but instead of the parameter '?' in the SQL set the value of ID.

    This is what I got:
    Code:
    begin
    
    declare idNumber INTEGER;
    
    for std as
    
    select ID idValue, SQL sqltext from TASKS
    
    do
    
    set idNumber = idvalue;
    
    execute immediate sqltext using idNumber;
    
    end;
    But i'm still failing. I tried: "execute immediate sqltext :idNumber" and so on, but it doesn't work. I've read about passing variables into sql and parameters '?' but no solution works. I'd be happy anyone explain what's wrong.

    Best regards,

    Mike

  2. #2
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    have a look in db2 sqllib/samples directory or in infocenter where they supply the same samples..
    http://www-01.ibm.com/support/knowle...3.html?lang=en
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •