Tuesday, June 19, 2007

FOR v2 AS
c2 CURSOR FOR
select distinct
a.userid,
RTRIM(char(MONTH(a.SESSIONSTARTON) ))
|| RTRIM(char(YEAR(a.SESSIONSTARTON))) as createdMth,
case
(
select distinct 1
from IBSADMIN.ActionAuditTrail aa,UserLoginAuditTrail ll
where
aa.LOGINTRAILID = ll.LOGINTRAILID
and aa.action ='auditAction.login'
and month(aa.createdOn) = 3
and year(aa.createdOn) = 2007
and ll.userid = a.userid
) when (1) then 1 else 0 end as status,
date(a.SESSIONSTARTON) as createdOn
from IBSADMIN.anonymousactionaudittrail a
where a.action ='auditAction.registration'
and month(a.SESSIONSTARTON) = 3
and year(a.SESSIONSTARTON) = 2007
and not exists
(
select 1
from ibsadmin.rpt_reguser_login rr
where rr.userid = a.userid
and rr.createdon =
RTRIM(char(MONTH(a.SESSIONSTARTON) ))
|| RTRIM(char(YEAR(a.SESSIONSTARTON)))
)and a.userid is not null
--end of Cursor

DO
--Inserting into Rpt table
INSERT INTO IBSADMIN.RPT_REGUSER_LOGIN
(USERID,CREATEDMTH,STATUS,CREATEDON)
VALUES (userid,createdMth,status,createdOn);
END FOR;
COMMIT;

No comments: