I have a stored procedure similar to something like this:
SELECT a.Name AS Author,
       b.Price,
       b.PublishDate,
       b.Title,
       b.ISBN
FROM   Book b
       INNER JOIN Author a ON b.Id = a.BookId
WHERE  a.Id = @authorId OR @author = 0
So when the input parameter @author is > 0 it returns records on a specific author, if 0 it returns records on every author.
Even when I pass any values greater than 0 for @author, the performance is sub-par (though it's not terribly slow). I then notice if I remove the OR clause the stored procedure runs much faster (at least 80% faster for the same input parameter). I then try to do something like:
IF @author > 0 
  --select records on a specific author
ELSE
  --select everything
However, the performance is pretty the same as OR. Is there anyway to code something like this in a different way to gain better performance?
 
     
     
     
    