Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to use sp_executesql
Message
De
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:
01415143
Vues:
51
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
?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform