I am working on my query to use Not In condition in my where clause but give me different result. below is a sample DDL and Desired result. thank you.
declare @s1 table
(line nvarchar(10),
location nvarchar(10)
)
INSERT @s1 VALUES('L3A','Bad')
INSERT @s1 VALUES('L3B','Bad')
INSERT @s1 VALUES('L3','Bad')
INSERT @s1 VALUES('L1','good')
INSERT @s1 VALUES('L2B','good')
INSERT @s1 VALUES('L3','good')
INSERT @s1 VALUES('L6','good')
INSERT @s1 VALUES('L6A','good')
INSERT @s1 VALUES('L3TR','bad')
INSERT @s1 VALUES('L3TR','bad')
INSERT @s1 VALUES('L3TR','good')
INSERT @s1 VALUES('L3TR','good')
INSERT @s1 VALUES('L3TR','good')
select
line, location
from @s1
where line not in ('L3A','L3B')
and (line in ('L3TR') and location not in ('Bad'))
or
select
line, location
from @s1
where line not in ('L3A','L3B')
and (line ='L3TR' and location='Good')
expected result.
line--- location
----------------
L3--- Bad
L1--- good
L2B--- good
L3--- good
L6--- good
L6A--- good
L3TR--- good
L3TR--- good
L3TR--- good