>Hi All,
>
>I need some help with an sql stored procedure. The procedure listed here passes a parameter to the Table Name and works as it should. What I also want to be able to do is to add a WHERE clause that passes two datetime parameters to filter the results to return rows that have a date field between the datetime parameters. I cannot seem to get thw where clause to work. Any help would be appreciated.
>
>
>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)
> --SET @StartDate = RTRIM(@StartDate)
> --SET @EndDate = RTRIM(@EndDate)
>
> Declare @cmd AS NVARCHAR(max)
>
> SET @cmd = N'Select * from ' + QUOTENAME(@TableName);
>
> exec sp_executesql @cmd;
>END
>
Please see
How to get information between datesand
http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/changing-exec-to-sp_executesql-doesn-t-phttp://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/avoid-conversions-in-execution-plans-by-
If it's not broken, fix it until it is.
My Blog