Name ID ID2 ID3 ID4 Match
1 BG234560 BB78458745
2 AC678900 BB7868877 ZZ5421896
3 AT9808744 BB546897
4 989878AC BBIIT9807 ZZ5874896
5 A9045678 BB748596
6 BB98076 AC9800876 ZZ2536987
7 ZZ8793456 YY879654 BB4587961
8 UIT90876 ZZ365289
9 BH98048474 YYCC123456 BB6584123
10 FT7849562 ZZ56980T ZZ6952314
11 3TY875759 BB258963
12 333IY78698 ZZ5463214
13 548I345 ZZ56980T BB254879
14 OPQ4567 BB45678 BB258963
15 2345YYY BB58214785
Name ID ID2 ID3 ID4 Match
2 AC678900 BB7868877 ZZ5421896
4 989878AC BBIIT9807 ZZ5874896
6 BB98076 AC9800876 ZZ2536987
7 ZZ8793456 YY879654 BB4587961
10 FT7849562 ZZ56980T ZZ6952314
13 548I345 ZZ56980T BB254879
14 OPQ4567 BB45678 BB258963
declare @Drug table ([Name] int, ID varchar(64), ID2 varchar(64), ID3 varchar(64), ID4 varchar(64), [Match] varchar(64))
insert into @Drug ([Name], ID, ID2, ID3, ID4, [Match])
select 1, 'BG234560', null, null, null, 'BB78458745' union all
select 2, 'AC678900', 'BB7868877', null, null, 'ZZ5421896' union all
select 3, 'AT9808744', null, null, null, 'BB546897' union all
select 4, '989878AC', null, 'BBIIT9807', null, 'ZZ5874896' union all
select 5, 'A9045678', null, null, null, 'BB748596' union all
select 6, 'BB98076', 'AC9800876', null, null, 'ZZ2536987' union all
select 7, 'ZZ8793456', 'YY879654', null, null, 'BB4587961' union all
select 8, 'UIT90876', null, null, null, 'ZZ365289' union all
select 9, 'BH98048474', null, 'YYCC123456', null, 'BB6584123' union all
select 10, 'FT7849562', 'ZZ56980T', null, null, 'ZZ6952314' union all
select 11, '3TY875759', null, null, null, 'BB258963' union all
select 12, '333IY78698', null, null, null, 'ZZ5463214' union all
select 13, '548I345', null, 'ZZ56980T', null, 'BB254879' union all
select 14, 'OPQ4567', 'BB45678', null, null, 'BB258963' union all
select 15, '2345YYY', null, null, null, 'BB58214785'
select *
from @Drug
where ID like 'BB%'
and ID like 'zz%'
and ID2 like 'BB%'
and ID2 like 'zz%'
and ID3 like 'BB%'
and ID3 like 'zz%'
and ID4 like 'BB%'
and ID4 like 'zz%'
Но это не дает вывода