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