====== pears.safedate ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create function "pears"."safedate"(
in "dd" char(30) )
returns char(30)
begin
declare "i" smallint;
declare "t","d","m" char(20);
if "dd" is null then
return null
end if;
set "dd" = "replace"("dd",'T',' ');
if "trim"("dd") = '' then
return null
end if;
if "charindex"('/',"dd") = 0 then
return "dd"
end if;
set "i" = "charindex"(' ',"dd");
if "i" > 0 then
set "t" = "stuff"("dd",1,"i"-1,'');
set "dd" = "left"("dd","i"-1)
else
set "t" = ''
end if;
set "i" = "charindex"('/',"dd");
set "d" = "left"("dd","i"-1);
set "dd" = "stuff"("dd",1,"i",'');
set "i" = "charindex"('/',"dd");
set "m" = "left"("dd","i"-1);
set "dd" = "stuff"("dd",1,"i",'');
return("string"("dd",'-',"m",'-',"d","t"))
end