简体   繁体   中英

SQL variable length numeric string

This query converts bc_int_phone to just numeric characters eliminating - and '' characters. Say the numbers obtained need not have the same starting numeric. Say I'm searching for 123-456-7890 but this could be of the form 999 123-456-7890.. How do I incorporate the like %(bc_phone_number)% in this code to incorporate this case?

select 
    ca.callingpartynumber, ca.originalcalledpartynumber, ca.duration,
    ca.duration_text, ca.finalcalledpartynumber,  
    case 
       when calledpartylastname is not null 
         then ca.calledpartylastname + ',' + calledpartyfirstname 
         else p1.name 
    end as calledpartyname,
    p1.location, p1.dept, p1.title,
    case 
       when callingpartylastname is not null 
         then ca.callingpartylastname + ',' + callingpartyfirstname 
         else p3.name 
    end as callingpartyname
from 
    calldata.calldetailreport ca
join 
    ps_bc_peoplesource_base p1 on ca.originalcalledpartynumber like replace(p1.bc_int_phone, '-', '')
left outer join 
    ps_bc_peoplesource_base p3 on ca.callingpartynumber like replace(p3.bc_int_phone, '-', '')
where 
    callingpartynumber in (select replace(bc_int_phone, '-', '') internal_modified  
                           from ps_bc_peoplesource_base 
                           where bc_lan_id like 'f7c')

try like ca.originalcalledpartynumber like '%'||replace(p1.bc_int_phone, '-', '')||'%'

|| is the concatenation operator for strings in oracle. USe + if you are using SQL Server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM