Quantcast
Channel: Obtimize this query
Viewing all articles
Browse latest Browse all 7

Obtimize this query

$
0
0

Try

SELECT [C].[ID] AS [ContentID], [C].[Name], [C].[URL] AS [URL]
FROM [dbo].[Content] AS C
WHERE C.ID = COALESCE(@Var1, @Var2)

This is assuming that you're passing two parameters but use the same field to compare.

Otherwise you may find these blogs helpful:

Do you use ISNULL(...). Don't, it does not perform - short blog by Denis Gobo
Dynamic Search Conditions in T-SQL Version for SQL 2008 (SP1 CU5 and later) - long and comprehensive article by Erland Sommarskog 
Catch All Queries - short blog by Gail Shaw
Sunday T-SQL tip: How to select data with unknown parameter set Nice blog by Dmitri Korotkevitch

Option recompile

Option recompile discussion thread

For every expert, there is an equal and opposite expert. - Becker's Law


My blog


Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>