title: MS SQL REPLACE not showing results
body: <p>Hey all i have the following query:</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>It returns no records... However, when i do this query:</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>It returns records..</p>
  
  <p>The phome number is formatted like:</p>
  
  <pre><code>for OnlineAppDetails: (xxx) xxx-xxxx
  for         tmpTable: xxx-xxx-xxxx
  </code></pre>
  
  <p>All i am doing is taking out the <strong>- ( ) and [space]</strong> in the phone number just to be sure i am being returned all the records i should be. I know there are matches in both tables so taking out <strong>- ( ) and [space]</strong> should still result in records returned.</p>
  
  <p><strong>update</strong></p>
  
  <p>Duh.... knew it was going to be simple.</p>
  
  <pre><code>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;
  </code></pre>