Search code examples
sqlcomparisonsql-like

SQL Server LIKE comparison


I have two tables in my database that I want to compare.

View image for better viewing: https://www.dropbox.com/s/rdn6kej6l9rk0lb/CapturaVendorClient.PNG

I want to compare if my knowledge_base.description contains any vendor.name values ​​and store them in another field of knowledge base called vendor_name (is still not created)

Example of knowledge_base.description: Client: Deutsche Bank
Vendor: Santa Fe - Singapore
Invoice: 025516

Example of vendor.name: Santa Fe

I tried using like and other tutorials on the net but did not work for me.

Something so you can compare like this:

SELECT * 
WHERE knowledge_base.descrition LIKE vendor.name

Solution

  • I think you need to create the crosswalk between Vendor and Knowledge_Base first, then inner join them so you can pull in the vendor name:

    SELECT KB.*, VN.VDescription
    FROM Knowledge_Base KB
    
    INNER JOIN 
       (
       select V.[Name] as VDescription, K.Description as KDescription
       FROM vendor, knowledge_base 
       where knowledge_base.description like '%' + vendor.name + '%'
       ) VN
    ON KB.Description = VN.KDescription