Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2015
    Posts
    2

    Unanswered: DB2 Hour as variable

    In my DB2 native Stored Procedure (SP), current query is :

    SET QUERY_TS = CURRENT TIMESTAMP - 1 HOUR;


    "1 hour" is the literal in the SP and I would like to have it replaced with a variable so that I can get the "hours" required from front end. Please advise me on how to get this working.

  2. #2
    Join Date
    May 2012
    Location
    Canberra, Australia
    Posts
    176
    Provided Answers: 6
    something along the lines of this?

    CREATE OR REPLACE PROCEDURE AM1 (IN HRS int)
    P1: BEGIN
    declare v_ts timestamp ;
    SELECT (current timestamp - HRS hour) into v_ts FROM SYSIBM.SYSDUMMY1;
    END P1
    Andy

    "All parts should go together without forcing. You must remember that the parts you are reassembling were disassembled by you. Therefore, if you can’t get them together again, there must be a reason. By all means, do not use hammer.” — IBM maintenance manual, 1975 "

  3. #3
    Join Date
    Aug 2015
    Posts
    2
    Quote Originally Posted by tafster View Post
    something along the lines of this?

    CREATE OR REPLACE PROCEDURE AM1 (IN HRS int)
    P1: BEGIN
    declare v_ts timestamp ;
    SELECT (current timestamp - HRS hour) into v_ts FROM SYSIBM.SYSDUMMY1;
    END P1
    Thank you so much . It worked. I was trying to use the variable in the SET statement and it never worked.

Tags for this Thread

Posting Permissions

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