Brian Tkatch wrote:
Ian Mackenzie wrote:
Hi Guys
I am VERY new to DB2 and have created a workingdays function to return
the working days between 2 dates, but I get some compiler errors when
running it:
CREATE FUNCTION WORKINGDAYS (STARTDATE, ENDDATE DATE) RETURNS INTEGER
DETERMINISTIC NO EXTERNAL ACTION
BEGIN ATOMIC
DECLARE DAYCOUNT INTEGER
SET (DAYCOUNT) = 0
WHILE (STARTDATE <= ENDDATE) DO
IF (DAYOFWEEK_ISO( STARTDATE) < 6) THEN
SET (COUNT) = (COUNT + 1)
END IF;
SET (STARTDATE) = (STARTDATE + 1 DAY)
END WHILE
RETURN DAYCOUNT
END
Does anyone know what I could do to fix this?
These are the errors I get:
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "SET" was found following "RE DAYCOUNT
INTEGER
". Expected tokens may include: "<SQL_variable_ declarations>". LINE
NUMBER=4. SQLSTATE=42601
SET (STARTDATE) = (STARTDATE + 1 DAY) END WHILE RETURN DAYCOUNT END
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "SET" was found following
"BEGIN-OF-STATEMENT".
Expected tokens may include: "SELECT". SQLSTATE=42601
SQL0104N An unexpected token "SET" was found following
"BEGIN-OF-STATEMENT". Expected tokens may include: "SELECT
Thank you very much!!!!!
Ian
1) Put semi-colons at the end of each command.
2) If you are using the CLP, and have not specified otherwise, put a
bacslash at the end of each line.
3) The IN parameter STARTDATE should have the word "DATE" after it.
B.
Thanks Brian!!!
Still having a problem though. I am running it in the Control Center in
windows, since I'm running it on a windows server 2003 machine -
Version 8.1
Trying this...
------------------------------ Commands Entered
------------------------------
CREATE FUNCTION WORKINGDAYS (STARTDATE DATE, ENDDATE DATE) RETURNS
INTEGER
DETERMINISTIC NO EXTERNAL ACTION
BEGIN ATOMIC
DECLARE DAYCOUNT INTEGER;
SET DAYCOUNT = 0;
WHILE (STARTDATE <= ENDDATE) DO
IF (DAYOFWEEK_ISO( STARTDATE) < 6) THEN
SET (COUNT) = (COUNT + 1);
END IF;
SET (STARTDATE) = (STARTDATE + 1 DAY);
END WHILE;
RETURN DAYCOUNT;
END;
------------------------------------------------------------------------------
CREATE FUNCTION WORKINGDAYS (STARTDATE DATE, ENDDATE DATE) RETURNS
INTEGER
DETERMINISTIC NO EXTERNAL ACTION
BEGIN ATOMIC
DECLARE DAYCOUNT INTEGER
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "INTEGER" was found following "MIC
DECLARE
DAYCOUNT". Expected tokens may include: "END-OF-STATEMENT". LINE
NUMBER=10.
SQLSTATE=42601
SET DAYCOUNT = 0
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "DAYCOUNT" was found following "SET ".
Expected
tokens may include: "JOIN <joined_table>" . SQLSTATE=42601
WHILE (STARTDATE <= ENDDATE) DO IF (DAYOFWEEK_ISO( STARTDATE) < 6) THEN
SET (COUNT) = (COUNT + 1)
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "WHILE (STARTDATE <= ENDDATE)" was found
following "BEGIN-OF-STATEMENT". Expected tokens may include:
"<labeled_begin _atomic>". SQLSTATE=42601
END IF
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "END-OF-STATEMENT" was found following
"END IF".
Expected tokens may include: "JOIN <joined_table>" . SQLSTATE=42601
SET (STARTDATE) = (STARTDATE + 1 DAY)
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "SET" was found following
"BEGIN-OF-STATEMENT".
Expected tokens may include: "SELECT". SQLSTATE=42601
END WHILE
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "END-OF-STATEMENT" was found following
"END
WHILE". Expected tokens may include: "JOIN <joined_table>" .
SQLSTATE=42601
RETURN DAYCOUNT
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "END-OF-STATEMENT" was found following
"RETURN
DAYCOUNT". Expected tokens may include: "JOIN <joined_table>" .
SQLSTATE=42601
END
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "END-OF-STATEMENT" was found following
"END".
Expected tokens may include: "JOIN <joined_table>" . SQLSTATE=42601
SQL0104N An unexpected token "END-OF-STATEMENT" was found following
"END". Expected tokens may include: "JOIN <joined_table >
Any help would be appreciated!!!! !!!!!1
Thanks
Ian