Hi,
I have the below result set from query 1. Now I need to count the key when the names are totally different for the same key (as highlighted below) if they are partially same (for ex siddharth and Sid) then we don’t need to count them.

Hi,
I have the below result set from query 1. Now I need to count the key when the names are totally different for the same key (as highlighted below) if they are partially same (for ex siddharth and Sid) then we don’t need to count them.

if they are partially same (for ex siddharth and Sid) then we don’t need to count them.
In database world there is not really something like "partially same"; data equals or not.
Please post some sample data as T-SQL script and the expected result.
Welcome to Microsoft Q&A!
Please refer below example and check whether it is working.
drop table if exists Search
create table Search
(name varchar(100),
[Thekey] int)
insert into Search values
('Blum,Kaye',294426789),
('BLUM,KAYE ELIZABETH',294426789),
('BAKER,MICHELLE',294739049),
('BOOT,DAMEN',294739049)
select count(distinct a.[Thekey]) count
from Search a
left join Search b
on a.[Thekey]=b.[Thekey]
where a.name not like '%'+b.name+'%'
and b.name not like '%'+a.name+'%'
OR
select count(distinct a.[Thekey]) count
from Search a
left join Search b
on a.[Thekey]=b.[Thekey]
where CHARINDEX(a.name,b.name)=0
and CHARINDEX(b.name,a.name)=0
If above is not working, please provide more sample data, details of rule and expected output.
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
15 people are following this question.
Year and Month aggregation in same Pivot table in SQL Server
SQL Server Query for Searching by word in a string with word breakers
How to show first row group by part id and compliance type based on priorities of Document type?
Query to list all the databases that have a specific user
T-sql query to find the biggest table in a database with a clustered index