可以使用 sql 服务器中的 where 在较小的单词中查找较大的单词

can use where in sql server to find bigger word in smaller word

我有一个 table 有一个像这样的列:(table1)

1-GM-100-20003-F01-N-1-2001   
1-GM-100-20013-F01-N-1-01
1-GM-100-20050-F01-N-1-1001

另一个 table 包含这些行(table2)

1-GM-100-20003-F01-N-1
1-GM-100-20013-F01-N-1
1-GM-100-20050-F01-N-1

如您所见,我可以在 table 2 行上使用 where 来查找类似于 table 1 值使用 like statement 的行,但我需要一些老虎钳反之亦然,我需要在 table1 中找到其中某些部分在 table1 中的行,例如

select * from table2 where table1Column contains table2 ???

例如,当我将 1-GM-100-20003-F01-N-1-2001 传递给来自 table1 的查询时,我希望我的查询 return this 1-GM-100-20003-F01-N-1

如果这些值有一个固定的长度(如果我算好这是一个 22 长度,你可以使用 sql 服务器中的 substring 方法来获取你的文本的一部分

select tbl2.*
from table2 tbl2
//... other stuff
where tbl2.table2column LIKE SUBSTRING(tbl1.column,0,22)

SUBSTRING 方法的语法和用法:

SUBSTRING ( expression ,start , length )

Select * form table where column like 'Your Conditions'

不支持这种类型的赞,大词在小词中找不到。

SQL 喜欢从更大的词中找出词的一部分