sql server 2012 - Procedure Advice -


i'm looking boost performance on 1 of our processes within production database. have 2 sets of sps configuration settings stored within configuration table.

an example syntax be:

declare @switch bit  if @switch = 1 insert dest_table_a  select values   source_table  if @switch = 2 insert dest_table_b select values   source_table 

would better practice in instance move if logic clause create standardized instead of logic having conditional within it?

e.g.

insert dest_table_a select values  source_table @switch = 1  insert dest_table_b select values source_table @switch = 2 

i appreciate might opinion piece curious see if else has had experience scenario.

the second example might lead parameter sniffing problem . (longer explanation here)

this issue created query optimizer generates execution plan optimized 1 of values of switch statement (and value send first time when call stored procedure).

in case, if call stored procedure @switch = 1 first time, execution plan parameter generated. subsequent calls @switch = 2 might take significantlty longer times process.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -