Table1
+---------------+
| varchar1 |
+---------------+
| aaa, aba, aab |
| aac, aca, caa |
+---------------+
Table2
+---------------+
| varchar2 |
+---------------+
| bbb, abb, aba |
| bbc, bcb, cbb |
+---------------+
如何比较来自2个不同表的varchar
以进行部分匹配?
aaa, aba, aab
Table1
与bbb, abb, aba
的{{1}}匹配,因为它们都包含Table2
。
答案 0 :(得分:0)
正如评论中所提到的,你真的应该将其正常化。这绝对是一个比解析这样的字符串更好的解决方案。但是,如果你真的想,你可以这样做:
Dim varchar1 As IEnumerable(Of String) = {"aaa, aba, aab", "aac, aca, caa"}
Dim varchar2 As IEnumerable(Of String) = {"bbb, abb, aba", "bbc, bcb, cbb"}
Dim varchar1Tokens As IEnumerable(Of String) = (From foo In varchar1
Let tokens = foo.Split(","c)
From bar In tokens
Select bar.TrimEnd)
Dim varchar2Tokens As IEnumerable(Of String) = (From foo In varchar2
Let tokens = foo.Split(","c)
From bar In tokens
Select bar.TrimEnd)
Dim matches As IEnumerable(Of String) = (From item In varchar1Tokens
Where varchar2Tokens.Contains(item)
Select item)
For Each match As String In matches
Console.WriteLine(match)
Next
Console.ReadLine()