Вы находитесь на странице: 1из 24

select DISTINCT

TRSC.RSCCODE,
TMemb.Clntcode,
TMemb.CertNo,
TMemb.suboffcode,
'01' as DepCode,
'M' as DepType,
TMemb.NameFirst,
TMemb.NameLast,
isnull(cast( TMemb.NameMid as char(2)), ' ') 'NameMid',
convert(char(8), TMemb.DOB, 112) 'DOB',
TMemb.Sex,
TMemb.status,
convert(char(8), TMemb.IniEffDt, 112) 'IniEffDt',
/* Case TMemb.Status
When 'T' Then convert(char(8), dateadd(dd, 1, TMemb.
EffDate), 112)
Else '99999999'
End 'TermDate', */
----BUG 1693 fix
Case TMemb.Status
When 'T' Then convert(char(8), TMemb.EffDate, 112)
Else '99999999'
End 'TermDate',
space(40) as Address1,
space(40) as Address2,
space(40) as Address3,
space(30) as State,
space(28) as City,
space(10) as ZipCode,
space(03) as HOMECNTRY,
space(16) as TelNo,
space(20) as MobileNo,
space(50) as EmailCode,
space(03) as Juriscnty,
space(40) as Juriscntyname, ---------UAT Updates
space(40) as Juriscity,
space(08) as JurCFDt,
space(01) as ChangeType,
space(03) as PriorJurCnty,
space(40) as PriorJurCity
into
#MemDepInitialActive
From
TMEMBER
TMemb,
TPOLICY
TPolc,
TRSCMATRIX TRSC
Where TMemb.ClntCode = TPolc.ClntCode
AND
TMemb.Rcdsts
= 'A'
AND
TPOLC.POLNO = TRSC.POLNO
AND
TRSC.RSCCODE ='MSO'
/*code change for RSC prod fix start*/
AND
TMemb.CertNo NOT IN (SELECT B.CERTNO FROM
TMULTIPL
ECOVMEM B
WHERE TM
emb.CLNTCODE=B.CLNTCODE )
/*code change for RSC prod fix end*/
AND
TMemb.Clntcode <> 'FEES'
-AND
TPolc.Polno between @Target_polno1 and @Target_polno2
AND
0 < ( SELECT COUNT(T2.CERTNO)
FROM TMEMPTPOL T2

WHERE T2.CERTNO = TMemb.CERTNO


AND T2.POLNO between @Target_polno1

-and @Target_polno2
AND
AND

T2.POLNO = TRSC.POLNO
TRSC.RSCCODE ='MSO'
AND T2.CLNTCODE = TMemb.CLNTCODE
AND ( T2.ProdCode LIKE 'CMM%'
/*code change for RSC pr

od fix start*/
/*OR T2.ProdCode LIKE
'DEN%'
OR T2.ProdCode LIKE 'OPT%'
OR T2.ProdCode LIKE 'RX%') */
OR T2.ProdCode = 'DEN'
OR T2.ProdCode = 'OPT'
OR T2.ProdCode = 'RX')
/*code change for RSC pr
od fix end*/
AND

T2.RcDSts

='A'

)
insert into #MemDepInitialActive
select
MemDep.RSCCODE ,
TDepn.Clntcode,
TDepn.CertNo,
-- /* 11/29 Change by Debamita for Enhancement 1645 that Dependent Suboffice cod
e should be blank*/
-(Select SubOffCode From TMEMBER Where ClntCode = TDepn.ClntCode a
nd CertNo = TDepn.CertNo),
space(03) as suboffcode,
TDepn.depcode,
TDepn.deptype,
TDepn.namefirst,
TDepn.namelast,
isnull(cast( TDepn.NameMid as char(2)), ' ') 'NameMid',
convert(char(8), TDepn.DOB, 112) 'DOB',
TDepn.sex,
TDepn.status,
convert(char(8), TDepn.Inieffdt, 112) 'IniEffDt',
/* Case TDepn.Status
When 'T' Then convert(char(8), dateadd(dd, 1, TD
epn.ChgEffDt), 112)
Else '99999999'
End 'TermDate', */
-----BUG 1693 fix
Case TDepn.Status
When 'T' Then convert(char(8), TDepn.ChgEffDt, 1
12)
Else '99999999'
End 'TermDate',
space(40) as Address1,
space(40) as Address2,
space(40) as Address3,
space(30) as State,
space(28) as City,
space(10) as ZipCode,
space(03) as HOMECNTRY,
space(16) as TelNo,
space(20) as MobileNo,
space(50) as EmailCode,

space(03) as Juriscnty,
space(40) as Juriscntyname, ---------UAT Updates
space(40) as Juriscity,
space(08) as JurCFDt,
space(01) as ChangeType,
space(03) as PriorJurCnty,
space(40) as PriorJurCity
from
TDEPENDENT TDepn,
#MemDepInitialActive MemDep
--TMultipleCovMem TMpCvgM
--code change for RSC pr
od fix
Where TDepn.ClntCode = MemDep.ClntCode
And
TDepn.CertNo = MemDep.CertNo
/*code change for RSC prod fix start*/
AND
TDepn.CertNo NOT IN (SELECT B.CERTNO FROM
TMULTIPLECOVMEM B
WHERE TDepn.CLNTCODE=B.C
LNTCODE )
/*code change for RSC prod fix end*/
And
TDepn.CLNTCODE <> 'FEES'
And
TDepn.rcdsts = 'A'
And
( 0 < (
select count(TMPT.ChgEffdt)
from TMemPtPol TMPT, TCOVERAGE C , TRSCMATRIX TRSC
where TMPT.PolNo = TRSC.POLNO and TRSC.RSCCODE ='MSO'
And TMPT.CertNo = TDepn.CertNO
And TMPT.ClntCode = TDepn.ClntCode
And ( TMPT.ProdCode LIKE 'CMM%'
/*code change for RSC prod fix s
tart*/
/*OR TMPT.ProdCode LIKE 'DEN%'
OR TMPT.ProdCode LIKE 'OPT%'
OR TMPT.ProdCode LIKE 'RX%') */
OR TMPT.ProdCode = 'DEN'
OR TMPT.ProdCode = 'OPT'
OR TMPT.ProdCode = 'RX')
/*code change for RSC prod fix e
nd*/
AND TMPT.RcDSts
= 'A'
AND TRSC.RSCCODE ='MSO'
and ((c.DEPMBIND
= 'Y' and TDepn.DepTYpe
= 'M') OR
(c.DEPSPIND
= 'Y' and TDepn.DepTYpe
= 'S') OR
(c.DEPCHIND
= 'Y' and TDepn.DepTYpe
= 'C') OR
((c.DEPPRIND = 'Y' or TMPT.CovgCode
= 'FAM') and TDepn.DepTYpe = 'P') OR
((c.DEPBSIND = 'Y' or TMPT.CovgCode
= 'FAM') and TDepn.DepTYpe = 'B') OR
((c.DEPOTIND6 = 'Y' or TMPT.CovgCode
= 'FAM') and TDepn.DepTYpe = '6') OR
((c.DEPOTIND7 = 'Y' or TMPT.CovgCode
= 'FAM') and TDepn.DepTYpe = '7') OR
((c.DEPOTIND8 = 'Y' or TMPT.CovgCode
= 'FAM') and TDepn.DepTYpe = '8') OR
((c.DEPOTIND9 = 'Y' or TMPT.CovgCode
= 'FAM') and TDepn.DepTYpe = '9') OR
((c.DEPOTIND10 = 'Y' or TMPT.CovgCode

= 'FAM') and TDepn.DepTYpe = 'O')


)
)
)
--SET MEMBER address from TMEMADDRUPDATE #MemDepInitialActive
Set Address1 = CAST( UPPER(ISNULL(b.ADDRESS1, '') )
as char(40) ),
Address2 = CAST( UPPER(ISNULL(b.ADDRESS2, '') ) as char(40)
),
Address3 = CAST( UPPER(ISNULL(b.ADDRESS3, '') ) as char(40)
),
State
= CAST( UPPER(ISNULL(b.State, '') ) as char(30) ),
City
= CAST( UPPER(ISNULL(b.City, '') ) as char(28) ),
ZipCode = CAST( UPPER(ISNULL(b.MailCode, '') ) as char(10)
),
HOMECNTRY = CAST( UPPER(ISNULL(b.CntyCode, '') ) as char(03)
),
TelNo
= CAST( UPPER(ISNULL(b.TELNO, '') ) as char(16) ),
MobileNo = CAST( UPPER(ISNULL(b.TELNO_MOBILE, '') ) as char(
20) ),
EmailCode = CAST( UPPER(ISNULL(b.EMAILCODE, '') ) as char(50)
),
Juriscnty = CAST( UPPER(ISNULL(b.JurisCntyCode, '') ) as char
(03) ),
Juriscity = CAST( UPPER(ISNULL(b.JurisCity, '') ) as char(40)
),
JurCFDt = isnull(convert(char(8), b.JurChgEffDt, 112), '')
FROM
#MemDepInitialActive a, TMEMADDR b
Where a.clntcode = b.clntcode
AND a.DepType = 'M'
AND
a.certno = b.certno
--SET DEPENDENT JURISDICTION
UPDATE #MemDepInitialActive
-- /*11/29 CHANGES START HERE FOR ENHANCEMENTS 1648 & 1649 that Juris Country,
City and Juris Eff date should be blank for dependents. For Juris Country COBOL
will be changed */
Set Juriscnty = CAST( UPPER(ISNULL(b.JurisCntyCode, '
') ) as char(03) )
-Juriscity = CAST( UPPER(ISNULL(b.JurisCity, '') )
as char(40) ),
-JurCFDt = isnull(convert(char(8), b.JurChgEffDt, 112), '')
FROM
#MemDepInitialActive a, TMEMADDR b
Where a.clntcode = b.clntcode
AND a.DepType <> 'M'
AND
a.certno = b.certno
/*
--- for Initial extract all the change type would be 'A'
Update #MemDepInitialActive
set ChangeType = 'A' */
/* UAT Updates change start */
UPDATE #MemDepInitialActive
Set Juriscntyname = CAST( UPPER(ISNULL(b.Cntyname, '') ) as char(
40) )
FROM
#MemDepInitialActive a, TCOUNTRY b
Where a.Juriscnty = b.Cntycode
AND
B.RCDSTS
= 'A'

UPDATE #MemDepInitialActive
Set Juriscntyname = ISNULL(Juriscntyname, space(40) )
/* REMOVE ',' FROM #MemDep Table as CSV will be re-formatted for any ','
found */
UPDATE #MemDepInitialActive
SET Address1 = REPLACE(Address1,',',' '),
Address2 = REPLACE(Address2,',',' '),
Address3 = REPLACE(Address3,',',' '),
State
= REPLACE(State,',',' '),
City
= REPLACE(City,',',' '),
ZipCode = REPLACE(ZipCode,',',' '),
TelNo
= REPLACE(TelNo,',',' '),
MobileNo = REPLACE(MobileNo,',',' '),
EmailCode= REPLACE(EmailCode,',',' '),
Juriscity= REPLACE(Juriscity,',',' '),
Juriscntyname= REPLACE(Juriscntyname,',',' '), ---------UAT Updates
NameFirst= REPLACE(NameFirst,',',' '),
NameLast = REPLACE(NameLast,',',' '),
NameMid = REPLACE(NameMid,',',' ')
/*--get member/dependent coverage from TMEMPTPOL */
select DISTINCT TMPol.clntcode, TMPol.certno, TMPol.polno, TMPol.prodcod
e, TMPol.benplncd, TMPol.covgcode,
case TMPol.prdstatus
When 'T' Then convert(char(8), TMPol.IniEffDt, 112)
Else convert(char(8), TMPol.CHGEFFDATE, 112)
End 'IniEffDt', ---this is actually the coverage effective date
/* case TMPol.prdstatus
When 'T' Then convert(char(8), dateadd(dd, 1, TMPol.CHGE
FFDATE), 112)
Else '99999999'
End 'TermDate', */
----BUG 1693 fix
case TMPol.prdstatus
When 'T' Then convert(char(8), TMPol.CHGEFFDATE, 112)
Else '99999999'
End 'TermDate',
TMPol.prdstatus
INTO #MemCovgInitialINTMDT
FROM TMemptpol TMPol, #MemDepInitialActive b, TPOLICY TPolc , TRSCMATRI
X TRSC
Where TMPol.ClntCode = b.ClntCode
and TMPol.certno
= b.certno
AND TMPol.PolNo
= TPolc.PolNo
AND TMPol.ClntCode = TPolc.ClntCode
-AND TMPol.CHGEFFDT >= @parm_start_date
AND TMPol.POLNO = TRSC.POLNO AND TRSC.RSCCODE ='MSO'
AND TMPol.Covgcode <> 'NOR'
and ( TMPol.ProdCode LIKE 'CMM%'
/*code change for RSC prod fix start*/
/*OR TMPol.ProdCode LIKE 'DEN%'
OR TMPol.ProdCode LIKE 'OPT%'
OR TMPol.ProdCode LIKE 'RX%') */
OR TMPol.ProdCode = 'DEN'
OR TMPol.ProdCode = 'OPT'
OR TMPol.ProdCode = 'RX')
/*code change for RSC prod fix end*/
AND TMPol.RcDSts
='A'

AND TPolc.RcdSts
='A'
ORDER BY TMPol.clntcode, TMPol.certno

--

Insert into #MemCovgInitialINTMDT


select DISTINCT
TMP.clntcode,
TMP.certno,
TMP.polno,
TMP.prodcode,
TMP.benplncd,
TMP.covgcode,
convert(char(8), TMP.CHGEFFDATE, 112),
'99999999',
TMP.prdstatus
FROM TMemptpol TMP, #MemDepInitialActive Q, TPOLICY R , TRSCMATRIX TRSC
Where TMP.ClntCode = Q.ClntCode
and TMP.certno
= Q.certno
AND TMP.PolNo
= R.PolNo
AND TMP.PolNo
= TRSC.POLNO AND TRSC.RSCCODE ='MSO'
AND TMP.ClntCode = R.ClntCode
AND TMP.POLNO between @Target_polno1 and @Target_polno2
AND TMP.Covgcode <> 'NOR'
AND ( TMP.ProdCode LIKE 'CMM%'
/*code change for RSC prod fix start*/
/*OR TMP.ProdCode LIKE 'DEN%'
OR TMP.ProdCode LIKE 'OPT%'
OR TMP.ProdCode LIKE 'RX%') */
OR TMP.ProdCode = 'DEN'
OR TMP.ProdCode = 'OPT'
OR TMP.ProdCode = 'RX')
/*code change for RSC prod fix end*/
AND TMP.RcDSts
= 'A'
AND TMP.prdstatus = 'A'
AND R.RcdSts
= 'A'
ORDER BY TMP.clntcode, TMP.certno
SELECT DISTINCT * INTO #MemCovgInitial
FROM #MemCovgInitialINTMDT
--drop the Intermidiate table
DROP TABLE #MemCovgInitialINTMDT ---coverage intermidiate table
--SELECT * FROM #MemDepInitialActive
--order by certno, depcode
--SELECT * FROM #MemCovgInitial
--order by certno
SELECT DISTINCT
B.clntcode,
B.PolNo,
B.certno,
A.depcode,
A.deptype
INTO #MemDepTempInitial
FROM #MemDepInitialActive A INNER JOIN #MemCovgInitial B
ON
A.CLNTCODE = B.CLNTCODE
AND A.CERTNO = B.CERTNO
ORDER BY B.clntcode, B.PolNo, B.certno, A.depcode

--select * from #MemDepTempInitial


CREATE TABLE #MemdepCovgInitial
(Clntcode
Char(05),
PolNo
Char(10),
Certno
Char(10),
Depcode
Char(03),
Deptype
Char(01),
AddChgInd Char(01), ----12/17
MedEffDt
Char(08),
MedEndDt
Char(08),
MEDPLAN
CHAR(03),
DENEffDt
Char(08),
DENEndDt
Char(08),
DENPLAN
CHAR(03),
OPTEffDt
Char(08),
OPTEndDt
Char(08),
OPTPLAN
CHAR(03),
RXEffDt
Char(08),
RXEndDt
Char(08),
RXPLAN
CHAR(03))
----- Define a CURSOR
e by one
Declare
@Cursor_Clntcode_Ini
@Cursor_Polno_Ini
@Cursor_Certno_Ini
@Cursor_Depcode_Ini
@Cursor_Deptype_Ini
@Med_Eff_Ini
@Med_Trm_Ini
@Med_Pln_Ini
@Den_Eff_Ini
@Den_Trm_Ini
@Den_Pln_Ini
@Opt_Eff_Ini
@Opt_Trm_Ini
@Opt_Pln_Ini
@Rxx_Eff_Ini
@Rxx_Trm_Ini
@Rxx_Pln_Ini
@MemDep_AddChg_IndINI

to fetch and process data from #MemDepCovgInitialINTMDT on


char(05),
char(10),
char(10),
char(03),
char(02),
char(08),
char(08),
char(03),
char(08),
char(08),
char(03),
char(08),
char(08),
char(03),
char(08),
char(08),
char(03),
char(01) ----12/17

DECLARE InitialExtract_Cursor CURSOR FOR


SELECT DISTINCT
T1.CLNTCODE
,T1.POLNO
,T1.CERTNO
,T1.DEPCODE
,T1.DEPTYPE
FROM #MemDepTempInitial T1
FOR READ ONLY
SET
SET
SET
SET
SET

@Cursor_Clntcode_Ini
@Cursor_Polno_Ini
@Cursor_Certno_Ini
@Cursor_Depcode_Ini
@Cursor_Deptype_Ini

=
=
=
=
=

NULL
NULL
NULL
NULL
NULL

SET
SET
SET
SET
SET
SET
SET
SET
SET
SET
SET
SET
SET

@MemDep_AddChg_IndINI
@Med_Eff_Ini
@Med_Trm_Ini
@Med_Pln_Ini
@Den_Eff_Ini
@Den_Trm_Ini
@Den_Pln_Ini
@Opt_Eff_Ini
@Opt_Trm_Ini
@Opt_Pln_Ini
@Rxx_Eff_Ini
@Rxx_Trm_Ini
@Rxx_Pln_Ini

=
=
=
=
=
=
=
=
=
=
=
=
=

'C' ---12/17
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL

OPEN InitialExtract_Cursor
FETCH NEXT FROM InitialExtract_Cursor
INTO @Cursor_Clntcode_Ini,
@Cursor_Polno_Ini,
@Cursor_Certno_Ini,
@Cursor_Depcode_Ini,
@Cursor_Deptype_Ini
WHILE @@FETCH_STATUS = 0
BEGIN --start of loop
---- Fetch Member/Dependent Add/Change Indicator
SELECT @MemDep_AddChg_IndINI = ISNULL(TR.ADDCHGIND, 'C')
FROM TRSCADDCHGIND TR
WHERE TR.CERTNO
= @Cursor_Certno_Ini
AND TR.CLNTCODE = @Cursor_Clntcode_Ini
AND TR.DEPCODE = @Cursor_Depcode_Ini
AND TR.ADDCHGIND = 'A'
IF @MemDep_AddChg_IndINI IS NULL
BEGIN
SET @MemDep_AddChg_IndINI = 'C'
END
SET @Med_Eff_Ini =

ISNULL((Select MAX(IniEffDt)
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
and A.prdstatus = 'A'
and A.ProdCode like 'CMM%'
and ((C.DEPMBIND
= 'Y' and @Cursor_Deptype_Ini =

'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR
((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR

((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') )
), SPACE(08) )
IF @Med_Eff_Ini <> SPACE(08)
BEGIN
SET @Med_Trm_Ini = SPACE(08)
SET @Med_Pln_Ini = (Select top 1 BenPlncd
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
and A.prdstatus = 'A'
and A.ProdCode like 'CMM%'
and ((C.DEPMBIND
= 'Y' and @Cursor_Deptype_Ini =
'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR
((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') ))
END
IF @Med_Eff_Ini = SPACE(08)
BEGIN
SET @Med_Trm_Ini = ISNULL((Select MAX(TERMDATE)
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
and A.prdstatus = 'T'
and A.ProdCode like 'CMM%'
and ((C.DEPMBIND
= 'Y' and @Cursor_Deptype_Ini =
'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND

= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR


((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') )
), SPACE(08) )
SET @Med_Eff_Ini = ISNULL((Select MAX(IniEffDt)
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
and a.TERMDATE = @Med_Trm_Ini
and A.prdstatus = 'T'
and A.ProdCode like 'CMM%'
and ((C.DEPMBIND
= 'Y' and @Cursor_Deptype_Ini =
'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR
((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') )
), SPACE(08) )
SET @Med_Pln_Ini = (Select TOP 1 BenPlncd
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
and a.TERMDATE = @Med_Trm_Ini
and A.prdstatus = 'T'
and A.ProdCode like 'CMM%'
and ((C.DEPMBIND
= 'Y' and @Cursor_Deptype_Ini =
'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND

= 'Y' and @Cursor_Deptype_Ini = 'C') OR


((C.DEPPRIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR
((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') ))
END
SET @Den_Eff_Ini = ISNULL((Select MAX(IniEffDt)
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
and A.prdstatus = 'A'
/*code change for RSC pr
od fix start*/
--and A.ProdCode like 'DEN%'
and A.ProdCode = 'DEN'
/*code change for RSC pr
od fix start*/
and ((C.DEPMBIND
= 'Y' and @Cursor_Deptype_Ini =
'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR
((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') )
), SPACE(08) )
IF @Den_Eff_Ini <> SPACE(08)
BEGIN
SET @Den_Trm_Ini = SPACE(08)
SET @Den_Pln_Ini = (Select top 1 BenPlncd
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini

and
and
and
and

A.certno
A.POLNO
A.COVGCODE
A.prdstatus

=
=
=
=

@Cursor_Certno_Ini
@Cursor_Polno_Ini
C.COVGCODE
'A'
/*code change for RSC pr

od fix start*/
--and A.ProdCode like 'DEN%'
and A.ProdCode = 'DEN'
/*code change for RSC pr
od fix start*/
and

((C.DEPMBIND

= 'Y' and @Cursor_Deptype_Ini =

'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR
((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') ))
END
IF @Den_Eff_Ini = SPACE(08)
BEGIN
SET @Den_Trm_Ini = ISNULL((Select MAX(TERMDATE)
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
and A.prdstatus = 'T'
/*code change for RSC pr
od fix start*/
--and A.ProdCode like 'DEN%'
and A.ProdCode = 'DEN'
/*code change for RSC pr
od fix start*/
and ((C.DEPMBIND
= 'Y' and @Cursor_Deptype_Ini =
'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR
((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7

= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR


((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') )
), SPACE(08) )
SET @Den_Eff_Ini = ISNULL((Select MAX(IniEffDt)
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
and a.TERMDATE = @Den_Trm_Ini
and A.prdstatus = 'T'
/*code change for RSC pr
od fix start*/
--and A.ProdCode like 'DEN%'
and A.ProdCode = 'DEN'
/*code change for RSC pr
od fix start*/
and ((C.DEPMBIND
= 'Y' and @Cursor_Deptype_Ini =
'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR
((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') )
), SPACE(08) )
SET @Den_Pln_Ini = (Select TOP 1 BenPlncd
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
and a.TERMDATE = @Den_Trm_Ini
and A.prdstatus = 'T'
/*code change for RSC pr
od fix start*/
--and A.ProdCode like 'DEN%'
and A.ProdCode = 'DEN'
/*code change for RSC pr
od fix start*/
and ((C.DEPMBIND
= 'Y' and @Cursor_Deptype_Ini =

'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR
((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') ))
END
SET @Opt_Eff_Ini = ISNULL((Select MAX(IniEffDt)
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
and A.prdstatus = 'A'
/*code change for RSC pr
od fix start*/
--and A.ProdCode like 'OPT%'
and A.ProdCode = 'OPT'
/*code change for RSC pr
od fix start*/
and ((C.DEPMBIND
= 'Y' and @Cursor_Deptype_Ini =
'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR
((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') )
), SPACE(08) )
IF @Opt_Eff_Ini <> SPACE(08)
BEGIN
SET @Opt_Trm_Ini = SPACE(08)

SET @Opt_Pln_Ini = (Select BenPlncd


From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
and A.prdstatus = 'A'
/*code change for RSC pr
od fix start*/
--and A.ProdCode like 'OPT%'
and A.ProdCode = 'OPT'
/*code change for RSC pr
od fix start*/
and ((C.DEPMBIND
= 'Y' and @Cursor_Deptype_Ini =
'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR
((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') ))
END
IF @Opt_Eff_Ini = SPACE(08)
BEGIN
SET @Opt_Trm_Ini = ISNULL((Select MAX(TERMDATE)
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
and A.prdstatus = 'T'
/*code change for RSC pr
od fix start*/
--and A.ProdCode like 'OPT%'
and A.ProdCode = 'OPT'
/*code change for RSC pr
od fix start*/
and ((C.DEPMBIND
= 'Y' and @Cursor_Deptype_Ini =
'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR
((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR

((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') )
), SPACE(08) )
SET @Opt_Eff_Ini = ISNULL((Select MAX(IniEffDt)
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
AND A.TERMDATE = @Opt_Trm_Ini
and A.prdstatus = 'T'
/*code change for RSC pr
od fix start*/
--and A.ProdCode like 'OPT%'
and A.ProdCode = 'OPT'
/*code change for RSC pr
od fix start*/
and ((C.DEPMBIND
= 'Y' and @Cursor_Deptype_Ini =
'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR
((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') )
), SPACE(08) )
SET @Opt_Pln_Ini = (Select TOP 1 BenPlncd
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
AND A.TERMDATE = @Opt_Trm_Ini
and A.prdstatus = 'T'
/*code change for RSC pr
od fix start*/
--and A.ProdCode like 'OPT%'
and A.ProdCode = 'OPT'

/*code change for RSC pr


od fix start*/
and

((C.DEPMBIND

= 'Y' and @Cursor_Deptype_Ini =

'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR
((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') ))
END
SET @Rxx_Eff_Ini = ISNULL((Select MAX(IniEffDt)
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
and A.prdstatus = 'A'
/*code change for RSC pr
od fix start*/
--and A.ProdCode like 'RX%'
and A.ProdCode = 'RX'
/*code change for RSC pr
od fix start*/
and ((C.DEPMBIND
= 'Y' and @Cursor_Deptype_Ini =
'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR
((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') )
), SPACE(08) )

IF @Rxx_Eff_Ini <> SPACE(08)


BEGIN
SET @Rxx_Trm_Ini = SPACE(08)
SET @Rxx_Pln_Ini = (Select top 1 BenPlncd
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
and A.prdstatus = 'A'
/*code change for RSC pr
od fix start*/
--and A.ProdCode like 'RX%'
and A.ProdCode = 'RX'
/*code change for RSC pr
od fix start*/
and ((C.DEPMBIND
= 'Y' and @Cursor_Deptype_Ini =
'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR
((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') ))
END
IF @Rxx_Eff_Ini = SPACE(08)
BEGIN
SET @Rxx_Trm_Ini = ISNULL((Select MAX(TERMDATE)
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
and A.prdstatus = 'T'
/*code change for RSC pr
od fix start*/
--and A.ProdCode like 'RX%'
and A.ProdCode = 'RX'
/*code change for RSC pr
od fix start*/
and ((C.DEPMBIND
= 'Y' and @Cursor_Deptype_Ini =
'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND

= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR


((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') )
), SPACE(08) )
SET @Rxx_Eff_Ini = ISNULL((Select MAX(IniEffDt)
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
AND A.TERMDATE = @Rxx_Trm_Ini
and A.prdstatus = 'T'
/*code change for RSC pr
od fix start*/
--and A.ProdCode like 'RX%'
and A.ProdCode = 'RX'
/*code change for RSC pr
od fix start*/
and ((C.DEPMBIND
= 'Y' and @Cursor_Deptype_Ini =
'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR
((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') )
), SPACE(08) )
SET @Rxx_Pln_Ini = (Select TOP 1 BenPlncd
From #MemCovgInitial A, TCOVERAGE C
Where A.clntcode = @Cursor_Clntcode_Ini
and A.certno
= @Cursor_Certno_Ini
and A.POLNO
= @Cursor_Polno_Ini
and A.COVGCODE = C.COVGCODE
AND A.TERMDATE = @Rxx_Trm_Ini
and A.prdstatus = 'T'
/*code change for RSC pr

od fix start*/
--and A.ProdCode like 'RX%'
and A.ProdCode = 'RX'
/*code change for RSC pr
od fix start*/
and

((C.DEPMBIND

= 'Y' and @Cursor_Deptype_Ini =

'M') OR
(C.DEPSPIND
= 'Y' and @Cursor_Deptype_Ini = 'S') OR
(C.DEPCHIND
= 'Y' and @Cursor_Deptype_Ini = 'C') OR
((C.DEPPRIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'P') OR
((C.DEPBSIND
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'B') OR
((C.DEPOTIND6
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '6') OR
((C.DEPOTIND7
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '7') OR
((C.DEPOTIND8
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '8') OR
((C.DEPOTIND9
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = '9') OR
((C.DEPOTIND10
= 'Y' or A.CovgCode = 'FAM') and @Cursor_Deptype_Ini = 'O') ))
END
---If the Plancodes
if @Med_Pln_Ini is
if @Den_Pln_Ini is
if @Opt_Pln_Ini is
if @Rxx_Pln_Ini is

are NULL, make them Spaces


NULL set @Med_Pln_Ini = space(03)
NULL set @Den_Pln_Ini = space(03)
NULL set @Opt_Pln_Ini = space(03)
NULL set @Rxx_Pln_Ini = space(03)

INSERT INTO #MemdepCovgInitial


SELECT @Cursor_Clntcode_Ini,
@Cursor_Polno_Ini,
@Cursor_Certno_Ini,
@Cursor_Depcode_Ini,
@Cursor_Deptype_Ini,
@MemDep_AddChg_IndINI,
@Med_Eff_Ini,
@Med_Trm_Ini,
@Med_Pln_Ini,
@Den_Eff_Ini,
@Den_Trm_Ini,
@Den_Pln_Ini,
@Opt_Eff_Ini,
@Opt_Trm_Ini,
@Opt_Pln_Ini,
@Rxx_Eff_Ini,
@Rxx_Trm_Ini,
@Rxx_Pln_Ini
SET
SET
SET
SET
SET
SET

@Cursor_Clntcode_Ini
@Cursor_Polno_Ini
@Cursor_Certno_Ini
@Cursor_Depcode_Ini
@Cursor_Deptype_Ini
@MemDep_AddChg_IndINI

=
=
=
=
=
=

NULL
NULL
NULL
NULL
NULL
'C'

SET
SET
SET
SET
SET
SET
SET
SET
SET
SET
SET
SET

@Med_Eff_Ini
@Med_Trm_Ini
@Med_Pln_Ini
@Den_Eff_Ini
@Den_Trm_Ini
@Den_Pln_Ini
@Opt_Eff_Ini
@Opt_Trm_Ini
@Opt_Pln_Ini
@Rxx_Eff_Ini
@Rxx_Trm_Ini
@Rxx_Pln_Ini

=
=
=
=
=
=
=
=
=
=
=
=

NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL

FETCH NEXT FROM InitialExtract_Cursor


INTO @Cursor_Clntcode_Ini,
@Cursor_Polno_Ini,
@Cursor_Certno_Ini,
@Cursor_Depcode_Ini,
@Cursor_Deptype_Ini
END

--END of loop

CLOSE InitialExtract_Cursor
DEALLOCATE InitialExtract_Cursor
--- Drop the Temporary table
Drop Table #MemDepTempInitial
Drop Table #MemCovgInitial
---Delete the entries in #MemdepCovgInitial where there is no Plan code i.e. wh
ere the member does not have
---any terminated / active coverage to be reportrd
Delete from #MemdepCovgInitial
where MedPlan = SPACE(03)
and DenPlan = SPACE(03)
and OptPlan = SPACE(03)
and RxPlan = SPACE(03)
/** for terminated dependents use dependent term date as the coverage en
d date**/
Update b
Set
MedEndDt = a.TermDate
FROM
#MemDepInitialActive a, #MemdepCovgInitial b
where a.clntcode = b.clntcode
and
a.certno = b.certno
and
a.depcode = b.depcode
and
a.depcode > 0 and a.status = 'T'
and
(b.MedEndDt > a.TermDate and MedEffDt <> '' )
Update
Set
FROM
where
and
and
and
and

b
DenEndDt = a.TermDate
#MemDepInitialActive a, #MemdepCovgInitial b
a.clntcode = b.clntcode
a.certno = b.certno
a.depcode = b.depcode
a.depcode > 0 and a.status = 'T'
(b.DenEndDt > a.TermDate and DenEffDt <> '' )

Update
Set
FROM
where
and
and
and
and

Update
Set
FROM
where
and
and
and
and

OptEndDt = a.TermDate
#MemDepInitialActive a, #MemdepCovgInitial b
a.clntcode = b.clntcode
a.certno = b.certno
a.depcode = b.depcode
a.depcode > 0 and a.status = 'T'
(b.OptEndDt > a.TermDate and OptEffDt <> '' )
RXEndDt = a.TermDate
#MemDepInitialActive a, #MemdepCovgInitial b
a.clntcode = b.clntcode
a.certno = b.certno
a.depcode = b.depcode
a.depcode > 0 and a.status = 'T'
(b.RXEndDt > a.TermDate and RXEffDt <> '' )

/** update dependent's effective where initial effective > member's cove
rage eff date **/
Update b
Set
MedEffDt = a.IniEffDt
FROM
#MemDepInitialActive a, #MemdepCovgInitial b
where a.clntcode = b.clntcode
and
a.certno = b.certno
and
a.depcode = b.depcode
and
a.depcode > 0
and
(b.MedEffDt < a.IniEffDt and MedEffDt <> '' )
Update
Set
FROM
where
and
and
and
and

Update
Set
FROM
where
and
and
and
and

Update
Set
FROM
where
and
and
and
and

DenEffDt = a.IniEffDt
#MemDepInitialActive a, #MemdepCovgInitial b
a.clntcode = b.clntcode
a.certno = b.certno
a.depcode = b.depcode
a.depcode > 0
(b.DenEffDt < a.IniEffDt and DenEffDt <> '' )
OptEffDt = a.IniEffDt
#MemDepInitialActive a, #MemdepCovgInitial b
a.clntcode = b.clntcode
a.certno = b.certno
a.depcode = b.depcode
a.depcode > 0
(b.OptEffDt < a.IniEffDt and OptEffDt <> '' )
RXEffDt = a.IniEffDt
#MemDepInitialActive a, #MemdepCovgInitial b
a.clntcode = b.clntcode
a.certno = b.certno
a.depcode = b.depcode
a.depcode > 0
(b.RXEffDt < a.IniEffDt and RXEffDt <> '' )

--SELECT* FROM #MemdepCovgInitial


--select * from #MemDepInitialActive
--- Join the basic Member / Dependent in for and Address Information along with
the
--- Coverage information to get the desired format of the Extract file
SELECT CAST( A.DepType
as char(01) ) as Deptype ,
CAST( A.Clntcode as char(05) ) as Client ,
CAST( A.certno
as char(10) ) as Certificate_Id ,
CAST( A.DepCode
as char(02) ) as Depcode ,
CAST( B.PolNo
as char(10) ) as Polno ,
CAST( A.namelast as char(50) ) as LastName ,
CAST( A.namefirst as char(50) ) as FirstName ,
CAST( A.NameMid
as char(02) ) as MiddleName ,
CAST( A.DOB
as char(08) ) as DOB ,
CAST( A.sex
as char(01) ) as Sex ,
CAST( B.MEDPLAN
as char(03) ) as MedPlan ,
CAST( B.MedEffDt as char(08) ) as MedEffDt ,
CAST( B.MedEndDt as char(08) ) as MedEndDt ,
CAST( B.DENPLAN
as char(03) ) as DENPLAN ,
CAST( B.DenEffDt as char(08) ) as DenEffDt ,
CAST( B.DenEndDt as char(08) ) as DenEndDt ,
CAST( B.OPTPLAN
as char(03) ) as OPTPLAN ,
CAST( B.OPTEffDt as char(08) ) as OPTEffDt ,
CAST( B.OPTEndDt as char(08) ) as OPTEndDt ,
CAST( B.RXPLAN
as char(03) ) as RXPLAN ,
CAST( B.RXEffDt
as char(08) ) as RXEffDt ,
CAST( B.RXEndDt
as char(08) ) as RXEndDt ,
--CAST( A.changetype as char(01) ) +
---12/17
CAST( B.AddChgInd as char(01) ) as AddChgInd ,
CAST( A.Status
as char(01) ) as Status ,
CAST( A.suboffcode as char(03) ) as suboffcode ,
CAST( A.address1 as char(40) ) as address1 ,
CAST( A.address2 as char(40) ) as address2 ,
CAST( A.address3 as char(40) ) as address3 ,
CAST( A.state
as char(30) ) as state ,
CAST( A.city
as char(28) ) as city ,
CAST( A.ZipCode
as char(10) ) as ZipCode ,
CAST( A.HOMECNTRY as char(03) ) as HOMECNTRY ,
CAST( A.TelNo
as char(16) ) as TelNo ,
CAST( A.MobileNo as char(20) ) as MobileNo ,
CAST( A.EmailCode as char(50) ) as EmailCode ,
CAST( A.Juriscnty as char(03) ) as Juriscnty ,
CAST( A.Juriscntyname as char(40) ) as Juriscntyname ,
CAST( A.Juriscity as char(40) ) as Juriscity ,
CAST( A.JurCFDt
as char(08) ) as JurCFDt ,
SPACE(08) + -- PLACE HOLDER FOR JURISDICTION EXPIRATION DATE
'*' AS RECORD_END , -- end of record marker
CAST( A.Juriscnty as char(03)) AS Juriscnty ,
CAST( A.PriorJurCnty as char(03)) AS PriorJurCnty ,
Case when A.Juriscnty in ( select JURISCNTRY from trscmatrix whe
re RSCCODE ='MSO' and enddate is not null )
Then 'Member still belongs to MSO'
else 'Member has been removed from this RSC'
end as Member_RSC_Relationship
--

AS

Initial_Extract_REC

--INTO #RSCExtractInitialTable
from #MemDepInitialActive A, #MemdepCovgInitial B , TRSCMATRIX TRSC
where A.clntcode = B.clntcode
AND
A.certno = B.certno
AND
A.depcode = B.depcode
AND
B.POLNO = TRSC.POLNO
AND
A.Juriscnty = TRSC.JURISCNTRY
AND
TRSC.RSCCODE ='MSO'
ORDER BY A.POLNO , A.CERTNO, A.DEPCODE
--DROP TABLE TEMPRSCExtractInitial
--SELECT A.* INTO TEMPRSCExtractInitial from

#MemDepInitialActive A

--select Initial_Extract_REC From #RSCExtractInitialTable


DROP TABLE #MemDepInitialActive
table
DROP TABLE #MemdepCovgInitial

---main member / dependent + Address info temp

Вам также может понравиться