TSQL-varchar max列在表中不包含字符串集

时间:2018-09-27 07:36:58

标签: sql-server tsql

我有两个表:

TableA  
(  
    id int identity(1,1),  
    maxString varchar(max)  
) 

TableB  
(  
    id int identity(1,1),  
    excludeString varchar(3072)  
) 

表A中的样本数据

|Id | maxString               |
|1  | abcdef \n ijk \n lmn \n |    --\n is a new line character  
|2  | nvc \n tre \n           | 

表B中的样本数据

|Id | excludeString |    
|1  | ijk           |  
问:我想从没有tableb“ excludestring”的TableA中选择行

在示例中,结果应为tableA中的第二行,因为它不包含“ ijk”

select * from TableA where maxstring does not contain (select excludestring from TableB).....

|Id | maxString     |
|2  | nvc \n tre \n |

1 个答案:

答案 0 :(得分:0)

这应该有效:

SELECT TableA.*
FROM TableA
LEFT JOIN TableB ON 1=1
WHERE TableA.maxString NOT LIKE '%' + TableB.excludeString + '%'