Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2010
    Posts
    1

    Unhappy Unanswered: MS SQL to DB2 SQL

    Hi,
    I have an problem creating an DB2 sql procedure on our AS400 5.4
    This is sql is direct copy past from a IBM DB2 redbook.
    You see the statement below, the error is:
    "...at token = is a syntax error ..."
    Q: What is wrong here?


    CREATE FUNCTION DEC2DATE (
    DATEDEC DECIMAL(8, 0) )
    RETURNS DATE
    LANGUAGE SQL
    DETERMINISTIC
    CONTAINS SQL
    RETURNS NULL ON NULL INPUT
    NO EXTERNAL ACTION
    BEGIN
    DECLARE RESULT DATE ;
    DECLARE InvalidDate CONDITION FOR '22007';
    DECLARE EXIT HANDLER FOR InvalidDate
    BEGIN
    RETURN CAST(NULL AS DATE);
    SIGNAL SQLSTATE '01HDI' SET MESSAGE_TEXT='Invalid date';
    END;
    SET RESULT = DATE(
    SUBSTRING(DIGITS(DATEDEC),1,4) || '-' ||
    SUBSTRING(DIGITS(DATEDEC),5,2) || '-' ||
    SUBSTRING(DIGITS(DATEDEC),7,2));
    RETURN RESULT;
    END ;

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    Maybe you didn't copy the example from a redbook for DB2 on AS/400 but rather some other DB2 product? Maybe you had a copy'n'paste error? It would help if you could provide some more details like which redbook, which version of DB2 you are using, and what the exact error message is, and how you handled the statement terminators.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

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
  •