I have a question about altering the where statements in the where clause based on a variable flag passed in by the UI.
In the scenario there are person records in the DB and the goal is to allow the user to find duplicates based on the criteria they select. It could be any permutation of the search options to be considered duplicates.
The query is simplified for the example, but the concept is the same. Would this be able to be included conditionally in the join using IF or CASE, or would each permutation need to be its own separate query?
Declare @lastnamedup varchar(1) = 'N',
@firstnamedup varchar(1) = 'N',
@DOBdup varchar(1) = 'N',
@SSNdup = 'N',
@ZIPdup= 'N'
/*UI values passed could set any to Y*/
select
p.id
p.lastname,
p.firstname,
p.SSN,
p.DOB,
p.Address1,
p.Address2,
p.zip
p.phone
from person p
join person p2 on p.id <> p2id
and /* conditionally join based on Dup flags activated
could be 1 or many of any of the 5 dup variables for example
@lastnamedup = 'Y' include and p.lastname = p2.lastname*/