日期:2014-05-16 浏览次数:20861 次
USE test
go
-->生成表A
if object_id('A') is not null
drop table A
Go
Create table A([ID] smallint,[ProdName] nvarchar(8))
Insert into A
Select N'1',N'宝马'
Union all Select N'2',N'宝马、奔驰、吉利'
Union all Select N'3',N'奥迪、奔腾'
Union all Select N'4',N'雪铁龙'
-->生成表B
if object_id('B') is not null
drop table B
Go
Create table B([ID] smallint,[ProdName2] nvarchar(2))
Insert into B
Select N'1',N'宝马'
Union all Select N'2',N'奔驰'
Union all Select N'3',N'宝马'
Union all Select N'4',N'吉利'
SELECT * FROM A
WHERE NOT EXISTS(SELECT 1 FROM B AS x WHERE CHARINDEX(x.ProdName2,a.ProdName)>0)
/*
ID ProdName
------ --------
3 奥迪、奔腾
4 雪铁龙
*/