Who is more efficient in a stored procedure
an IF ... ELSE to change the where clause or add a condition in where to evaluate if put a condition
Examples.
SELECT *
FROM table
WHERE monto = 100
AND ( @canal IS NULL OR canal = @canal )
OR
IF @canal IS NULL
BEGIN
SELECT *
FROM table
WHERE monto = 100
END
ELSE
BEGIN
SELECT *
FROM table
WHERE monto = 100
AND canal = @canal
In personal opinion, without being an expert I think the first example is the best option, but I not have a lot of experience in sql
Or maybe exist another best solution.
Please help me, because I wanna optimize a stored-procedure