====== pears.WPKMaintainGetSwitchValue ====== Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace. ===== Original SQL ===== create function "pears"."WPKMaintainGetSwitchValue"( /* Application Maintained Function / Procedure - DO NOT EDIT*/ in "SwitchID" char(20),in "SwitchLocation" char(20),in "SwitchSource" char(1) ) returns long varchar begin declare "rv" long varchar; declare "param" char(100); declare "def" long varchar; declare "i" smallint; declare "tp" char(1); if "switchsource" not in( 'L','P' ) then -- Only Literal and Params maintained in this way return null end if; set "rv" = null; set "switchlocation" = "trim"("switchlocation"); if "switchlocation" = 'Global' or "switchlocation" = '' then set "switchlocation" = null end if; if "switchlocation" is not null then -- For maintenance we are just interested in the branch setting - we do NOT fall back to the global select first "value" into "rv" from "wpkglobalswitchsetting" where "wpkglobalswitchid" = "switchid" and "location" = "switchlocation" else if "switchsource" = 'L' then select first "value" into "rv" from "wpkglobalswitchsetting" where "wpkglobalswitchid" = "switchid" and "location" = 'Global'; if "rv" is null then select "value" into "rv" from "wpkglobalswitch" where "wpkglobalswitchid" = "switchid" end if else select "value" into "def" from "wpkglobalswitch" where "wpkglobalswitchid" = "switchid"; set "i" = "charindex"(';',"def"); if "i" > 0 then set "param" = "left"("def","i"-1); set "def" = "right"("def","length"("def")-"i") else set "param" = "def"; set "def" = null end if; execute immediate with batch off "string"('select first ',"param",' into rv from params'); if "trim"("isnull"("rv",'')) = '' then set "rv" = "def" end if end if end if; if "trim"("isnull"("rv",'')) <> '' then select "datatype" into "tp" from "wpkglobalswitch" where "wpkglobalswitchid" = "switchid"; if "tp" = 'B' then if "ucase"("left"("trim"("rv"),1)) in( '1','Y','T' ) then set "rv" = 'Y' else set "rv" = 'N' end if end if end if; return "rv" end