Using a REPLACE function in a SELECT CASE query

时间:2019-04-17 01:54:11

标签: sql

I am writing a script where the cable_no is the foreign key to the other tables that I will be joining. An example of the cable_no may look like this "A01234567B". However, the cable_no in other tables is "A01234567" (basically its the same record without the B at the end) How do I construct my script such that I remove all the "B" in the cable_no before joining to other tables?

select cc.riser_fid as RISER_FID, cc.cbl_fid as ZH_CBL_FID, f.cable_no AS ZH_CBL_NAME, FM.FACILITY_ID as FACILITY_ID, FC.CHANNEL_ID AS CHANNEL_ID, 
ft.FACILITY_TRAIL_ITM_ID AS FACILITY_TRAIL_ITM_ID, ft2.parent_fac_trl_itm_id as parent_fac_trl_itm_id, FT2.TRAIL_SEQ_NO, FT2.A_SITE_ID, ft2.asgn_channel_id,
CASE WHEN 
F.CABLE_NO LIKE '%B' REPLACE('B', '')
,CASE 
    WHEN ft2.a_site_id = a.a_site_id then 1 
    else null
END EXIST_IN_GTECH
from sgtel10.connected_cables cc
JOIN gc_fcbl_temp f on f.g3e_fid = cc.cbl_fid AND f.ltt_id in (0,888888888)
JOIN FACILITY_MASTER_TEMP FM ON FM.FACILITY_NAME = f.cable_no 
JOIN FACILITY_CHANNEL_TEMP FC ON FC.FACILITY_ID = FM.FACILITY_ID AND FC.CHANNEL_ID IS NOT NULL
JOIN FACILITY_TRAIL_ITEMS_TEMP ft on ft.facility_trail_itm_id = fc.facility_trail_itm_id
JOIN FACILITY_TRAIL_ITEMS_TEMP ft2 on ft2.parent_fac_trl_itm_id = ft.parent_fac_trl_itm_id and ft2.trail_seq_no = 1.0
LEFT JOIN A_SITE_ID A ON A.A_SITE_ID = FT2.A_SITE_ID)
;

1 个答案:

答案 0 :(得分:0)

You can do something like this:

t1 join
t2
on t1.cable_no = t2.cable_no || 'B'

|| is the standard operator for string concatenation.