Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Stored Procedure
Message
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Database:
MS SQL Server
Divers
Thread ID:
01433610
Message ID:
01433619
Vues:
68
This message has been marked as the solution to the initial question of the thread.
>>>I didn't look too close yet, but looks like there is an extra comma at the end of cmd line - not sure how did it get there.
>>
>>Right, I took out the extra commas, and it saved successfully, but when I tried to run it, I get this:
>>
>>Must declare the scalar variable "@StartDate".
>
>Getting this error right now - give me a sec.

Of course!!!

Here is the correct version
alter PROCEDURE [dbo].[GetWellData] 
	-- Add the parameters for the stored procedure here	
	@Tablename sysname,	 
	@StartDate datetime,
	@EndDate datetime
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from interfering with SELECT statements.
	SET NOCOUNT ON;
	SET @TableName = RTRIM(@TableName)

	Declare @cmd AS NVARCHAR(max)
   DECLARE @ParmDefinition NVARCHAR(500)
   SET @ParmDefinition = N'@InnerStartDate datetime ,@InnerEndDate datetime'

	SET @cmd = N'Select top 10 * from ' + QUOTENAME(@TableName) + ' where BidDateTime between @InnerStartDate and @InnerEndDate'
    
	exec sp_executesql @cmd, @ParmDefinition,
            @InnerStartDate = @StartDate,
            @InnerEndDate  = @EndDate
END
go

execute GetWellData 'Bid', '20080801','20091101'
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