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

Obtimize this query

$
0
0

First create

create index for id column with include ContentID,Name,URL

Next:

SELECT [C].[ID] AS [ContentID], [C].[Name], [C].[URL] AS [URL]
FROM [dbo].[Content] AS C
where 
[C].[ID] = isnull((@VAR1),'0')--  and @VAR1 IS NOT NULL
union all
SELECT [C].[ID] AS [ContentID], [C].[Name], [C].[URL] AS [URL]
FROM [dbo].[Content] AS C
where [C].[ID] = isnull((@VAR2),'0') 

Note : Assumption .1. Id does not have 0 value. 

2. It will work better if you expect more null value  else you canuse coalesec function describe by Steven Wang


Viewing all articles
Browse latest Browse all 7

Trending Articles