i've often come across situations where i can write the conditions of a t-sql query like this...
DECLARE @FirstName NVARCHAR(500)
SET @FirstName ='Joe'
SELECT *
FROM dbo.Customers c
WHERE
CASE
WHEN @FirstName <> '' THEN
CASE WHEN c.FirstName= @FirstName THEN 1 ELSE 0 END
ELSE 1
END = 1
Or like this...
SELECT *
FROM dbo.Customers c
WHERE
(@FirstName = '' OR (@FirstName <> '' AND c.FirstName = @FirstName))
They both produce the same results and both query plans appears to be the same.
So i'm curious as to which one is best practice or if there are any pitfalls with one over the other?