Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Stored Procedure
Message
From
06/11/2009 14:51:46
 
General information
Forum:
ASP.NET
Category:
Databases
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Database:
MS SQL Server
Miscellaneous
Thread ID:
01433610
Message ID:
01433620
Views:
65
>>>>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
>
>
>-- Test query
>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'@StartDate datetime ,@EndDate datetime'
>
>	SET @cmd = N'Select * from ' + QUOTENAME(@TableName) + ' where BidDateTime between @StartDate and @EndDate'
>    
>	exec sp_executesql @cmd, @ParmDefinition,
>            @StartDate = @StartDate,
>            @EndDate  = @EndDate
>END
>go
>
>execute GetWellData 'Bid', '20081001','20091101'
That did it, Thanks Naomi.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform