嘿,我有以下查询:
SELECT REPLACE(REPLACE(REPLACE(REPLACE(tmpTable.Caller_Number,'-',''),'(',''),')',''),' ','')
FROM tmpTable
WHERE EXISTS
(SELECT REPLACE(REPLACE(REPLACE(REPLACE(OnlineAppDetails.addPhone,'-',''),'(',''),')',''),' ','')
FROM OnlineAppDetails
WHERE OnlineAppDetails.addPhone = tmpTable.Caller_Number)
ORDER BY GroupsBy ASC;
它不返回任何记录...但是,当我执行此查询时:
SELECT *
FROM tmpTable
WHERE EXISTS
(SELECT * FROM OnlineAppDetails
WHERE SUBSTRING(OnlineAppDetails.addPhone,2,3)+'-'+SUBSTRING(OnlineAppDetails.addPhone,7,4)+SUBSTRING(OnlineAppDetails.addPhone,11,4) = tmpTable.Caller_Number)
ORDER BY GroupsBy ASC;
它返回记录..
电话号码的格式如下:
for OnlineAppDetails: (xxx) xxx-xxxx
for tmpTable: xxx-xxx-xxxx
我所做的只是去掉电话号码中的- ( ) 和 [空格],以确保我得到了我应该得到的所有记录。我知道两个表中都有匹配项,因此取出- ( ) 和 [space]仍应导致返回记录。
更新
呃....知道这很简单。
SELECT *
FROM tmpTable
WHERE EXISTS
(SELECT *
FROM OnlineAppDetails
WHERE REPLACE(REPLACE(REPLACE(REPLACE(OnlineAppDetails.addPhone,'-',''),'(',''),')',''),' ','') = REPLACE(REPLACE(REPLACE(REPLACE(tmpTable.Caller_Number,'-',''),'(',''),')',''),' ',''))
ORDER BY GroupsBy ASC;