Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Stored Procedure
Message
 
À
06/11/2009 14:51:46
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:
01433634
Vues:
39
>>>>>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.

If you use BETWEEN to check a date range, you must be sure that there cannot be any null values in either of those date columns. If either date field is NULL, the row will not be selected.
Linda Harmes
HiBit Technologies, Inc.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform