Академический Документы
Профессиональный Документы
Культура Документы
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
-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
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
--
@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
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
'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
'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)
((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'
((C.DEPMBIND
'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) )
od fix start*/
--and A.ProdCode like 'RX%'
and A.ProdCode = 'RX'
/*code change for RSC pr
od fix start*/
and
((C.DEPMBIND
'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
@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
--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 <> '' )
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