嘿,我有以下查詢:MS SQL REPLACE不顯示結果
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;
它返回的記錄。 。
的PHOME號碼的格式如下:
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;
Gotcha。在OP中更正。 – StealthRT