Здравствуйте, я получаю сообщение об ошибке в заголовке.Проблема возникает из-за того, что исходный тип данных - varchar.У меня проблемы с преобразованием полей 'CA_Admitted_TG' и 'Prev_CA_Admitted_TG' в varchar.Где во всем этом коде я могу внести изменения?Я попытался преобразовать их в заявлениях объявления.
Declare @UWD table
(RB_IND varchar(30)
,CY_Eff_Yr_Mnth varchar(7)
,CY_Eff_Prior_3Mnth_Ind varchar(1)
,Tier_Grp int
,NB_WP money
,RB_WP money
,NB_MP money
,RB_MP money
,Expired_WP money
,RB_Prev_WP money
,RB_Prev_MP money
,NB_Pol_Cnt int
,RB_Pol_Cnt int
,Expired_Pol_Cnt int)
insert into @UWD
Select case when NB_IND = 'CN' then Prev_RB_IND
else RB_Ind
End
,case when NB_IND = 'CN' then PY_Exp_Yr_Mnth
else CY_Eff_Yr_Mnth
End
, Case when NB_IND = 'CN' then PY_Exp_Prior_3mnth_Ind
else CY_Eff_Prior_3Mnth_Ind
End
, Case when NB_IND = 'CN' then Prev_CA_Admitted_TG
else CA_Admitted_TG
End
, sum(case when NB_Ind = 'NB' then WrittenPrem else 0 end)
, sum(case when NB_Ind = 'RB' then WrittenPrem else 0 end)
, sum(case when NB_Ind = 'NB' then ManualPrem else 0 end)
, sum(case when NB_Ind = 'RB' then ManualPrem else 0 end)
, sum(case when NB_Ind = 'RB' then WrittenPrem
when NB_IND = 'CN' then Prev_WrittenPrem
else 0 end)
, sum(case when NB_Ind = 'RB' then Prev_WrittenPrem else 0 end)
, sum(case when NB_Ind = 'RB' then Prev_ManualPrem else 0 end)
, sum(case when NB_IND='NB' then 1 else 0 end)
, sum(case when NB_IND='RB' then 1 else 0 end)
, sum(case when NB_Ind <> 'NB' then 1 else 0 end)
From dbo.EPLI_Tracking_Rpt_Data
where NB_Ind in ('RB', 'NB', 'CN')
and ((case when NB_IND = 'CN' then Prev_RB_IND
else RB_Ind
End) = 'CA Admitted')
group by (case when NB_IND = 'CN' then Prev_RB_IND
else RB_Ind
End)
,(case when NB_IND = 'CN' then PY_Exp_Yr_Mnth
else CY_Eff_Yr_Mnth
End)
,(Case when NB_IND = 'CN' then PY_Exp_Prior_3mnth_Ind
else CY_Eff_Prior_3Mnth_Ind
End)
,(Case when NB_IND = 'CN' then Prev_CA_Admitted_TG
else CA_Admitted_TG
End)
Declare @CN table
(Prev_RB_IND varchar(30)
,PY_Exp_Yr_Mnth varchar(7)
,PY_Exp_Prior_3Mnth_Ind varchar(1)
,CN_qt_TG int
,CN_qt_WP money
,CN_qt_MP money
,CN_expired_WP money
,CN_expired_MP money)
Insert into @CN
select a.Prev_RB_INd
,a.PY_Exp_Yr_Mnth
,a.PY_Exp_Prior_3mnth_Ind
,b.CA_Admitted_TG
,sum(b.quotedprem) as CN_qt_WP
,sum(b.Quoted_ManualPrem) as CN_qt_MP
,sum(a.Prev_WrittenPrem)
,sum(a.Prev_ManualPrem)
from dbo.EPLI_Tracking_Rpt_Data a
inner join dbo.EPLI_Tracking_Rpt_SQB_RB b
on a.prev_Pol_Num = b.prevpolicynum
where a.NB_IND='CN' and b.Quoted = 1 and b.Bound = 0 and a.Prev_RB_INd ='CA Admitted'
group by a.Prev_RB_INd
,a.PY_Exp_Yr_Mnth
,a.PY_Exp_Prior_3mnth_Ind
,b.CA_Admitted_TG
Select RB_IND
, CY_Eff_Yr_Mnth
, CY_Eff_Prior_3Mnth_Ind
, Tier_Grp
, NB_WP as NB_Prem
, RB_WP as RB_Prem
, NB_MP as NB_ManualPrem
, RB_MP as RB_ManualPrem
, Expired_WP as Expired_Prem
, RB_Prev_WP as Prev_WrittenPrem
, RB_Prev_MP as Prev_ManualPrem
, NB_Pol_Cnt
, RB_Pol_Cnt
, Expired_Pol_Cnt
, b.Prev_RB_IND
, b.PY_Exp_Yr_Mnth
, b.PY_Exp_Prior_3mnth_Ind
, b.CN_qt_TG
, CN_qt_WP
, CN_qt_MP
, CN_expired_WP
, CN_expired_MP
from @UWD a
full join @CN b
on a.RB_IND = b.Prev_RB_IND
and a.CY_Eff_Yr_Mnth = b.PY_Exp_Yr_Mnth
and a.CY_Eff_Prior_3Mnth_Ind = b.PY_Exp_Prior_3Mnth_Ind
and a.Tier_Grp = b.CN_qt_TG