Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Stored Procedure
Message
 
 
À
06/11/2009 15:01: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:
01433626
Vues:
32
Test it with various dates - the ones that should return data and the ones what don't.

>>>Please take the time to mark her message as the solution so others can learn by it.
>>>
>>>Thanks!
>>
>>BTW, I corrected again my version - Jim, please review the procedure. I think we do need to use different variables - e.g. in the second version I changed them to InnerStartDate, etc. again - I either got confused too much or something was not working in my tests properly.
>Here is the completed sp.
>
>set ANSI_NULLS ON
>set QUOTED_IDENTIFIER ON
>GO
>-- =============================================
>-- Author:		ATSI
>-- Create date: 11/5/2009
>-- Description:	Procedure to retrieve all data from the selected table between the selected dates
>-- =============================================
>ALTER PROCEDURE [dbo].[GetWellData] 
>	-- Add the parameters for the stored procedure here	
>	@Tablename sysname,
>	@StartDate as datetime,
>	@EndDate as datetime
>
>AS
>BEGIN
>	-- SET NOCOUNT ON added to prevent extra result sets from interfering with SELECT statements.
>	SET NOCOUNT ON;
>
>	Declare @cmd AS NVARCHAR(max)
>	Declare @ParamDefinition NVARCHAR(500)
>
>	SET @ParamDefinition = N'@StartDate datetime, @EndDate datetime'
>	SET @cmd = N'Select * from ' + QUOTENAME(@TableName) + 'WHERE Date between @StartDate And @EndDate'
>    
>	exec sp_executesql @cmd, @ParamDefinition,
>		@StartDate = @StartDate,
>		@EndDate = @EndDate
>END
>
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform