Since you are interested only in whether or not a record exists, you could drop all the expensive operators, replacing them with cheaper alternatives:
If ( EXISTS (
SELECT * FROM aDT WHERE theFN = @pF and theIN = @pI and theLN = @pL and theANA = @pLY
))
BEGIN
SET @Bool = 1
RETURN @Bool
END
If ( EXISTS (
SELECT * FROM aDT2 WHERE theFN = @pF and theIN = @pI and theLN = @pL and theANA = @pLY
))
BEGIN
SET @Bool = 1
RETURN @Bool
END
IF ( EXISTS (
SELECT *
FROM tblUA
INNER JOIN tblUs ON tblUA.fldULK = tblUs.fldUID
INNER JOIN tblFs ON tblUs.fldFK = tblFs.fldFID
WHERE (tblFs.fldFN = @pF) AND (tblFs.fldIN = @pI ) AND (tblUs.fldLN = @pL ) AND (tblUA.fldANA = @pL)
))
BEGIN
SET @sDup = 1
RETURN @sDup
END
The result should be equivalent without DISTINCT
s or GROUP BY
/HAVING
, because your results are binary: DISTINCT
/GROUP BY
clauses can change the exact record count, but they cannot change the outcome of the EXISTS
operator.