I know the solution should be around the forums somewhere, but I've been staring at this code for 3 hours and am sure I'm missing something simple. Am Running SQL Server 2k5. Am Attempting to Recall all water useage details between two dates, just cant get the dates formatted properly and am still learning T-SQL (Am transitioning first DB from Access to SQL Server)Input is Start and Finish Date in Format YYYYMMDD. If No Date is entered, pick up all recordsTable DefHolding_ID VarCharMeter_ID VarCharStartD DateTimeEndD DateTimeRate FloatTarif VarCharDays IntAverage_Rate FloatTotal_Water_.. FloatTotal_Value Float/* Begin Procedure */ALTER PROCEDURE dbo.Return_UseageBetweenDates (@sdate int, @ldate int)AS -- Add the parameters for the stored procedure here SET DATEFORMAT DMY DECLARE @sql nvarchar(MAX); BEGIN --Force Unknown Config Variables SET ANSI_NULLS ON; SET QUOTED_IDENTIFIER ON; -- Prevent extra result sets from interfering with SELECT statements. SET NOCOUNT ON; SET @sql = ' SELECT Holding_ID, Meter_ID, MIN(StartD) AS Start_Date, MAX(EndD) AS End_Date, Rate, SUM(Days) AS Total_Days, Tarif, SUM(Total_Water_Used) AS T_Water_Used, CAST(SUM(Total_Value) AS money) AS T_Value, AVG(Average_Rate) AS Weighted_Average FROM dbo.Temp_StateChange WHERE StartD >= ISNULL(' SET @sql = @sql + @sdate SET @sql = @sql + ', 01011900) AND EndD < ISNULL(' SET @sql = @sql + @ldate SET @sql = @sql + ', 99991231) GROUP BY Meter_ID, Holding_ID, Rate, Tarif;' EXEC sp_executesql @sqlEND