Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to use sp_executesql
Message
 
 
À
28/07/2009 14:50:48
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:
01415144
Vues:
46
>Thank for answer Naomi.
>
>Only one question.
>
>IS this two codes has 1 execution plan:
>
>
> DECLARE @Col2 SMALLINT, @Col1 INT
> DECLARE @SQL NVARCHAR(1000)
> SELECT @SQL = 'select * from dbo.test
> where Col2 = @InnerCol2 and Col1 = @InnerCol1'
> DECLARE @ParmDefinition NVARCHAR(500)
> SET @ParmDefinition = N'@InnerCol2 smallint ,@InnerCol1 int'  
>
> --change param values and run the same query
>  SELECT @Col2 = 2,@Col1 = 3
>  EXEC SP_EXECUTESQL  @SQL,@ParmDefinition,
>              @InnerCol2  = @Col2,
>              @InnerCol1  = @Col1
>
>
>and
>
>
> DECLARE @Col2 SMALLINT, @Col1 INT
> DECLARE @SQL NVARCHAR(1000)
> SELECT @SQL = 'select * from dbo.test
> where Col2 = @InnerCol2 and Col1 = @InnerCol1'
> DECLARE @ParmDefinition NVARCHAR(500)
> SET @ParmDefinition = N'@InnerCol2 smallint ,@InnerCol1 int'  
>
> --change param values and run the same query
>  EXEC SP_EXECUTESQL  @SQL,@ParmDefinition,
>              @InnerCol2  = 4,
>              @InnerCol1  = 5
>
>
>?

AFAIK they should have the same execution plan, I can run the tests later tonight.

Do you have an access to SSMS - can you test the execution plan?
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