Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2007
    Posts
    50

    Question Unanswered: How to select a varible (in a resultset)

    How can I select a variable into a resultset?
    Something like:

    BEGIN
    DECLARE myVar varchar(100);
    SELECT myVar;
    END;

  2. #2
    Join Date
    Sep 2007
    Posts
    50
    I found something that seems to work, which is select varibale from sysibm.sysdummy1
    Is this a good practice?

  3. #3
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    "SELECT var;" is not SQL - hence, DB2 does not support it. At least that is good practice.

    The purpose of SYSIBM.SYSDUMMY1 is exactly to do what you have in mind. Alternatively, you can do this:
    Code:
    SET ... = myVar;
    Or this:
    Code:
    VALUES ( myVar );
    The latter works on DB2 LUW but not on DB2 z/OS V8 and earlier.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  4. #4
    Join Date
    Sep 2007
    Posts
    50
    Fantastic!

    Thanks

Posting Permissions

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