SQL 服务器连接 LIKE 或

SQL Server connecting LIKE with or

有没有办法连接 SQL 中的 LIKE 语句并选择最接近的情况,例如我有:

FROM Report JOIN SortedData ON Report.ProductDecription LIKE  
'%' + '(%' + SortedData .Products + '%' +  SortedData.Products + '%' + ChemicalsSorted.Products + '%' + ChemicalsSorted.Products + '%)' + '%'
|'%' + '(%' + ChemicalsSorted.Products + '%' +  ChemicalsSorted.Products + '%' + ChemicalsSorted.Products + '%)' + '%'
|'%' + '(%' + ChemicalsSorted.Products + '%' + '%' +  ChemicalsSorted.Products + '%)' + '%'
|'%' + '(%' + ChemicalsSorted.Products + '%)' + '%' 
|'%' + ChemicalsSorted.Products + '%' +  ChemicalsSorted.Products + '%' + ChemicalsSorted.Products + '%' + ChemicalsSorted.Products + '%'
|'%' + ChemicalsSorted.Products + '%' +  ChemicalsSorted.Products + '%' + ChemicalsSorted.Products + '%' 
|'%' + ChemicalsSorted.Products + '%' +  ChemicalsSorted.Products + '%'
|'%' + ChemicalsSorted.Products + '%'

我得到的错误是:

Msg 402, Level 16, State 1, Line 5 The data types varchar and text are incompatible in the add operator.

有什么方法可以将它们连接在一起吗?或沿线的某物。

如果我从你的 "code" 那里了解到你正在尝试做什么,你会这样做:

ON SomeColumn LIKE '%This%'
OR SomeColumn LIKE '%That%'
OR SomeColumn LIKE '%Other%'

首先您必须像接下来那样编辑您的加入:

SELECT Field1, Field2
FROM Table1
INNER JOIN Table2 ON Table1.ID=Table2.TID 
WHERE ( yourField like '%aa%' OR yourField like '%bb%')

将字段更改为您的字段