Brian,

Since you have dates like this throughout your database I strongly suggest
you create a UDF so that you do not have to bury this logic into each
query.

Someone else can pretty up the error handling of this. By prettying up I
mean convert the error into some default value, like null.

STRSQL
CREATE FUNCTION ROB/INTTODATE
(INTDATE INT)
RETURNS DATE
LANGUAGE SQL
RETURNS NULL ON NULL INPUT
BEGIN
DECLARE CHARDATE CHAR(8);
DECLARE RETURNDATE DATE;
SET CHARDATE = CAST(INTDATE AS CHAR(8));
SET RETURNDATE = DATE(SUBSTR(CHARDATE, 1, 4) CONCAT '-' CONCAT
SUBSTR(CHARDATE, 5, 2) CONCAT '-' CONCAT
SUBSTR(CHARDATE, 7, 2));
RETURN RETURNDATE;
END
Function INTTODATE was created in ROB.

SELECT INTTODATE(CAST (20071001 AS INT)) from sysibm/sysdummy1
....+....1
INTTODATE
2007-10-01
******** End of data ********
SELECT statement run complete.
SELECT INTTODATE(CAST (20071032 AS INT)) from sysibm/sysdummy1
Query cannot be run. See lower level messages.


Rob Berendt

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].