Most efficient way to cancel or avoid select in union query?
What is more efficient, using one scalar variable as in the previous example or using IF sentences and create specific queries as in the example below?


In SQL Server a query plan may not vary based on the parameters passed (unless you disable plan caching with OPTION RECOMPILE).  So whenever you want different plans, you need seperate queries.