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