Try this:create table dbo.yourtable ( id int not null ,name1 varchar(80) null ,name2 varchar(80) null ,primary key (id));insert into dbo.yourtable values (1,'JAY JOHN SMITH','JOHN SMITH JAY') ,(2,'JAY JOHN SMITH','SMITH JOHN JAY') ,(3,'MR JAY JOHN SMITH','SMITH JOHN JAY');with cte as (select id ,1 as col ,case when charindex(' ',name1)>0 then substring(name1,1,charindex(' ',name1)-1) else name1 end as name1 ,case when charindex(' ',name1)>0 then substring(name1,charindex(' ',name1)+1,len(name1)-charindex(' ',name1)) else null end as name2 from dbo.yourtable union all select id ,2 as col ,case when charindex(' ',name2)>0 then substring(name2,1,charindex(' ',name2)-1) else name2 end as name2 ,case when charindex(' ',name2)>0 then substring(name2,charindex(' ',name2)+1,len(name2)-charindex(' ',name2)) else null end as name2 from dbo.yourtable union all select id ,col ,case when charindex(' ',name2)>0 then substring(name2,1,charindex(' ',name2)-1) else name2 end as name1 ,case when charindex(' ',name2)>0 then substring(name2,charindex(' ',name2)+1,len(name2)-charindex(' ',name2)) else null end as name2 from cte where name2 is not null )select * from yourtable as a where not exists (select * from cte as b left outer join cte as c on c.id=b.id and c.col=2 and c.name1=b.name1 where b.id=a.id and b.col=1 and c.id is null ) order by id;
If you want records that matches (all words), leave the red "not", if you want records that doesn't match (all words), remove the red "not".