potworspaghetti
potworspaghetti

Reputation: 1

SQL Server : compare two string

I need to compare two strings and find difference. My first table is t1.address, second table t2 contains suppliers it is address but from 3 columns t2.adres + ' ' + t2.code + ' ' +t2.place .

Example:

'Mlodziencza 36  03-655 Warszawa' t1.adres

'Mlodziencza 36  03-655 Warszawa' t2.adres+'  '+t2.code+' '+t2.place

Using my query I have 1120 rows in this year but most of them are the same only few are different. When I change in query <> to = in t1.Kl_adres <> t2.adres+' '+t2.code+' '+t2.place `, I get 0 rows so they are all different and this is not true.

select t1.Kl_adres,t2.adres+'  '+t2.code+' '+t2.place,*  
from t1, t2 
where t1.Kl_code=t2.gruan+':'+t2.konto 
  and t1.year='2014'
  and t1.Kl_adres<>t2.adres+'  '+t2.code+' '+t2.place 
order by id desc

Upvotes: 0

Views: 89

Answers (1)

Hamlet Hakobyan
Hamlet Hakobyan

Reputation: 33381

Try this:

SELECT t1.Kl_adres, 
       t2.adres+'  '+t2.code+' '+t2.place, *  
FROM t1
  JOIN t2 
    ON t1.Kl_code=t2.gruan+':'+t2.konto 
WHERE
   t1.year='2014'
   and t1.Kl_adres<>t2.adres+'  '+t2.code+' '+t2.place

Upvotes: 0

Related Questions