====== pears.NotificationsExist ====== Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace. ===== Original SQL ===== create function "pears"."NotificationsExist"( /* Application Maintained Function / Procedure - DO NOT EDIT*/ in "pTemplateid" char(50),in "pDeptid" char(2),in "pNotificationType" char(20),in "pRecipientType" char(20) ) returns tinyint begin if exists(select * from "NotificationTemplate" where "isnull"("Defunct",0) = 0 and "NotificationType" = "pTemplateID" and "isnull"("divisionid",'') = any(select "DivisionID" from "DivisionsAllowed") and "NotificationType" like "pNotificationType" and "RecipientType" like "pRecipientType" and("isnull"("ownerid","userstaffid") = "userstaffid") and((not exists(select * from "NotificationDepartment" as "d" where "d"."NotificationTemplateid" = "NotificationTemplate"."NotificationTemplateid")) or((not exists(select * from "NotificationDepartment" as "d" where "d"."NotificationTemplateid" = "NotificationTemplate"."NotificationTemplateid")) or(exists(select * from "NotificationDepartment" as "d" key join "department" as "dd" where "d"."NotificationTemplateid" = "NotificationTemplate"."NotificationTemplateid" and "dd"."departmentid" like "pdeptid" and "isnull"("dd"."DivisionID",'') = any(select "DivisionID" from "DivisionsAllowed")))))) then return 1 else return 0 end if end