使用从左到右匹配参考号和在sql

时间:2016-11-06 08:48:20

标签: sql sql-server

如何匹配从左到右的参考编号

使用SQL Server 2008

表1

参考值1

ABC123456

表2

定2

EFABC123456
ACDERERERE
ABC12345693843

我们想要将reference1与reference2表格从左到右进行比较

预期行为

表2

Reference2

EFABC123456 - Not match
ACDERERERE - Not match
ABC12345693843 - Match (its matching the complete reference from left to right with reference1 )

如何查询逻辑

尝试查询

Left(@pi_ref, Len(table1.refno)) = table1.refno then RTRIM(LTRIM(table1.refno))

此查询适用于完整的参考编号,而不是从左到右

请协助

1 个答案:

答案 0 :(得分:1)

table2.refno like table1.refno + '%'