Hi guys,
Please have a look at the codes below:
there are 2 cases statements in this select which looks amateur query
,
one is in select and one is in join,
is there a way to change case statement become variable or something.
My short question would be how to simplify this.
Thanks in advance,
Please have a look at the codes below:
Code:
select std.intern_instrument_rating, std.guarantor_pd, std.mitigant_lgd, std.object_key_value, std.lot_id,
std.object_origin, fg.facility_grade_type,std.char_cust_element3, fg.object_key_value,std.mitigant_exposure_class,
case when ms.secc_type = 'Internal : Basic Scale <= 500k' then 1
when ms.secc_type = 'Internal : Expanded Scale >500k' then 2
else 'error' end as grade_conv,
std.intern_instrument_rating_type
from maintable std
join
t_risk_object_facility_grade fg
on std.object_key_value=fg.object_key_value
and std.object_origin = fg.object_origin
and std.intern_instrument_rating_type = fg.facility_grade_type
join
etl_staging_db..s_master_scale_backup ms
on ms.secc = std.intern_instrument_rating
and case when ms.secc_type = 'Internal : Basic Scale <= 500k' then 1
when ms.secc_type = 'Internal : Expanded Scale >500k' then 2
else 'error' end = std.intern_instrument_rating_type
and (ms.lgd <> std.mitigant_lgd or ms.pd <> std.guarantor_pd)
order by 1
there are 2 cases statements in this select which looks amateur query

one is in select and one is in join,
is there a way to change case statement become variable or something.
My short question would be how to simplify this.
Thanks in advance,