Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to use sp_executesql
Message
 
 
À
28/07/2009 10:09:30
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01415047
Message ID:
01415049
Vues:
56
Sergey,

I do not see much of a difference here and don't think there would be any difference in optimizing.

Please read http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/avoid-conversions-in-execution-plans-by-

and

http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/changing-exec-to-sp_executesql-doesn-t-p

for more in depth discussion.

>Hello All.
>What code is more likely for SQL Server query optimizer :
>
>
>DECLARE @IntVariable INT;
>DECLARE @SQLString NVARCHAR(500);
>DECLARE @ParmDefinition NVARCHAR(500);
>
>/* Build the SQL string one time. */
>SET @SQLString =
>     N'SELECT * FROM AdventureWorks.Sales.Store WHERE SalesPersonID = @SalesID';
>/* Specify the parameter format one time. */
>SET @ParmDefinition = N'@SalesID int';
>
>/* Execute the string with the first parameter value. */
>SET @IntVariable = 275;
>EXECUTE sp_executesql @SQLString, @ParmDefinition,
>                      @SalesID = @IntVariable;
>
>or
>
>
>DECLARE @IntVariable INT;
>DECLARE @ParmDefinition NVARCHAR(500);
>
>/* Build the SQL string one time. */
>SET @SQLString =
>     N'SELECT * FROM AdventureWorks.Sales.Store WHERE SalesPersonID = @SalesID';
>/* Specify the parameter format one time. */
>SET @ParmDefinition = N'@SalesID int';
>
>/* Execute the string with the first parameter value. */
>SET @IntVariable = 275;
>EXECUTE sp_executesql N'SELECT * FROM AdventureWorks.Sales.Store WHERE SalesPersonID = @SalesID',
>          @ParmDefinition,
>          @SalesID = @IntVariable;
>
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform