====== pears.IQXNetStringToDate ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
COMMENT TO PRESERVE FORMAT ON PROCEDURE "pears"."IQXNetStringToDate" IS
'create function IQXNetStringToDate
/* Application Maintained Function / Procedure - DO NOT EDIT*/
( in "sdate" char(20) )
returns date
begin
declare "rv" date;
declare "i" smallint;
declare "d" smallint;
declare "m" smallint;
declare "y" smallint;
set "sdate" = "trim"("sdate");
if "sdate" regexp ''^\\d{4}\\-.*'' then -- ISO format
set "y" = cast("left"("sdate",4) as smallint);
set "sdate" = "stuff"("sdate",1,5,'''');
set "i" = "charindex"(''-'',"sdate");
if "i" <= 1 then
return null
end if;
set "m" = cast("left"("sdate","i"-1) as smallint);
set "sdate" = "stuff"("sdate",1,"i",'''');
set "d" = cast("sdate" as smallint)
else -- UK format with optional preceding day name
set "i" = "charindex"('' '',"sdate");
if "i" > 0 then -- Day name to be removed before parsing date
set "sdate" = "trim"("stuff"("sdate",1,"i",''''))
end if;
set "i" = "charindex"(''/'',"sdate");
if "i" <= 1 then
return null
end if;
set "d" = cast("left"("sdate","i"-1) as smallint);
set "sdate" = "stuff"("sdate",1,"i",'''');
set "i" = "charindex"(''/'',"sdate");
if "i" <= 1 then
return null
end if;
set "m" = cast("left"("sdate","i"-1) as smallint);
set "sdate" = "stuff"("sdate",1,"i",'''');
set "y" = cast("sdate" as smallint)
end if;
return "ymd"("y","m","d")
exception
when others then return null
end'