Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2006

    Question Unanswered: Selecting a variable table name, how to do it?

    for a simple embedded SQL query in Cobol like this:
    Depending on parameter given, if parameter = 1, I need to run this query:
    select * from file1
    if the parameter = 2, i need to run this query:
    select * from file2

    the name of the "file" is fixed but the number depends on the parameter. How can I achieve it? I can't use the colon sign like we do it for conditions, at the table selection level.

  2. #2
    Join Date
    Jan 2007
    Jena, Germany
    You must build your SQL statement in a string and process it as dynamic SQL, i.e. prepare the statement, possibly describe it, ...
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  3. #3
    Join Date
    Oct 2006
    May I know what's the command line to use in a cobol programme to execute a SQL statement? I'm running on AS400 now.

    My problem is, the query is actually part of the cursor which is embedded into my Cobol programme.

  4. #4
    Join Date
    Jun 2006
    input parameter : eg. var1 keeping value '1'
    you could do :
    var2='file'||var1 or concatenate string with variable
    or with conditional create var2
    if var1 =1 then
    var3='select * from '||var2
    exec sql prepare xxx from var3
    exec sql declare ci1 cursor for xxx
    exec sql open cursor C1
    Best Regards, Guy Przytula
    DB2 UDB LUW certified V6/7/8

Posting Permissions

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