Thanks, George it indeed reduced the time.
I face a tricky situation, what if the variable is 2 or more?
declare @id varchar(max), @name varchar(max)
set @id = '1, 2, 3, 4, 5'
set @name = 'Washington, Jefferson, Lincoln'
select *
from table1
where (@id is null or
exists (select 1 from...