Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

Optimizing a Stored Proc with IF-THEN Conditional logic

$
0
0

Suppose you have three queries. The SP will only run one of them, based on IF-Then logic

if @p1 = 1 SELECT....FROM .....

ELSE if @p1 = 2 SELECT....FROM .....

ELSE if @p1 = 3 SELECT....FROM .....

Now if it were only one query instead of three I'm sure the optimizer would usually do a good job of creating, and caching, a suitable plan (probably 90% of the time).

Is the optimizer just as reliable (say 90%) when there are three queries involved? Or is it more likely, in this scenario, that two of the queries will NOT get optimized?




Viewing all articles
Browse latest Browse all 8428

Trending Articles



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