PARSENAME function in SQL Server

Problem Statement:- I have two columns one column contains a value with string as comma-separated like ‘James, Sawyer’ and another column contains like James. So get an output the third column as true if the value within the first column contains in the second column

Solution:-

— CASE TABLE FOR CHECKING SCENARIO NAMED check_n

create table check_n

(comb_name varchar(20),

name varchar(10)

);

— INSERT SOME ROWS INTO THE TABLE AS PER THE REQUIREMENT

insert into check_n values(‘James,Sawyer’,’James’);

insert into check_n values(‘James,Sawyer’,’Sawyer’);

insert into check_n values(‘James,Sawyer’,’Jamey’);

select * from check_n;

select

comb_name , name ,

case

when name=x.first_name or name = x.second_name then ‘true’

else ‘false’

end as condition_check from (

select comb_name , name,

PARSENAME(REPLACE(comb_name, ‘,’, ‘.’), 1) AS first_name,

PARSENAME(REPLACE(comb_name, ‘,’, ‘.’), 2) AS second_name

from check_n) x

RESULT:-