Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2012
    Posts
    6

    Unanswered: Variable declaration

    Is it possible to declare all this part in a variable declaration ?
    TIMESTAMP(current date, TIME('00.00.00')) - 15 MONTHS + 1 DAYS

    I have many delete statements in my script and I want to reuse it in a variable.
    For ex:
    CREATE VARIABLE D_TIME TIME;

    SET D_TIME = TIMESTAMP(current date, TIME('00.00.00')) - 15 MONTHS + 1DAYS;

    DELETE from U_ContactAttr where (EnvelopeID,ContainerID) in
    (select EnvelopeID,ContainerID from U_Envelope where ContactDateTime < DTIME);

    DELETE from U_Contact where (EnvelopeID,ContainerID) in
    (select EnvelopeID,ContainerID from U_Envelope where ContactDateTime < DTIME);

    DROP VARIABLE D_TIME;

    COMMIT;

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    You have to declare the variable in a compound statement. And it only has scope within that compound statement. But it should work as you want.

    Andy

  3. #3
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Quote Originally Posted by ARWinner View Post
    You have to declare the variable in a compound statement. And it only has scope within that compound statement. But it should work as you want.
    I would rephrase that as "you can also declare a variable in a compound statement, in which case it would only have scope within that compound statement". Since DB2 9.7 global variables are supported -- they are catalog objects.

    CREATE VARIABLE statement - IBM DB2 9.7 for Linux, UNIX, and Windows
    ---
    "It does not work" is not a valid problem statement.

  4. #4
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    As we are still on V9.5, I did not know that. I learned something. Thanks.

    Andy

Posting Permissions

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