ALTER TRIGGER [dbo].[gl_courselog_iscounted_update]
ON [dbo].[testcourselog]
AFTER INSERT,UPDATE
AS
DECLARE @roleid int
select @roleid = testusers.roleid FROM testusers,deleted d where testusers.userid=d.userid
print @roleid
DECLARE @r int
select @r = count(*) from inserted
IF UPDATE(grade) and @r > 0
BEGIN
IF @r = 1
BEGIN
SET NOCOUNT ON;
UPDATE testcourselog SET iscounted=1 FROM testcourselog t JOIN deleted d ON t.courselogid = d.courselogid
AND (
SELECT ISNULL(
(SELECT value FROM gl_security_users where gl_security_users.userid=d.userid
AND gl_security_users.securityid=281),
(isnull((SELECT value FROM gl_security_roles where gl_security_roles.roleid=@roleid
AND gl_security_roles.securityid=281),
(SELECT defaultvalue from gl_security where securityid=281)))
)
)=1
END
ELSE
BEGIN
UPDATE testcourselog SET iscounted=1 FROM testcourselog t JOIN deleted d ON t.courselogid = d.courselogid
AND (
SELECT ISNULL(
(SELECT value FROM gl_security_users where gl_security_users.userid=d.userid
AND gl_security_users.securityid=281),
(isnull((SELECT value FROM gl_security_roles where gl_security_roles.roleid=@roleid
AND gl_security_roles.securityid=281),
(SELECT defaultvalue from gl_security where securityid=281)))
)
)=1
END
END
|