Blog

Share this blog : twitter

Feb 16

Written by: IOTAP ::-- Database Team
2/16/2010 6:48 PM 

This Blog will explain, how to avoid dynamic query to improve performance.


Whenever developer executes a query, it goes through following steps
1. Checking validity of Query
2. Creation of execution plan of Query
3. Actual execution of Query


If developer writes Stored Procedure, first 2 steps are already done while Stored Procedure creation. So Stored procedure is always faster than executing query in code behind. But due to some reason if developer writes “Dynamic Query” in Stored Procedure , then every time store procedure execution goes through all the above 3 steps .


Following are some of the scenarios in which developer writes Dynamic Query.


Scenarios:
1. When Input parameters for a store procedure are having multiple values [Comma Separated Values].
2. When Input parameters for a store procedure are having multiple values and Database table column on which data gets filtered is dynamically decided as per input parameter to stored Procedure.

Developer can avoid first scenario by using “XML” data type to create temporary table and then use this temporary table to filter multivalue data. For second scenario again developer can use “XML” data type, temporary table with “Case” statement to decide column at run time.


For any clarifications or for further information, please email us at info@iotap.com.

Tags:

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 


 
 
 

IOTAP is an IT Consulting and Software Services Company with global delivery centers in Mumbai and Chennai, India. We are a Microsoft Gold Certified Partner and use products and technologies like Dynamics CRM, SharePoint, Silverlight, and the .Net platform to create solutions that help our customers connect, communicate and collaborate effectively