title: error in converting datetime from character string in sql server 2005
body: <p>I'm facing problems in passing the date parameters.</p>
  
  <p>I'm getting the error </p>
  
  <blockquote>
    <p><em>Conversion failed when converting datetime from character string.</em></p>
  </blockquote>
  
  <p>My stored procedure is the below, please let me know what to do, </p>
  
  <pre><code>ALTER PROCEDURE [dbo].[WEEKLY_REPORT_PROC](
      @START_DATE DATETIME,
      @END_DATE     DATETIME,@PRACTISE_NAME NVARCHAR(MAX))--,
      -- @D1 DECIMAL(5,2),
      -- @D2 DECIMAL(5,2),
      -- @D3 DECIMAL(5,2),
      -- @D4 DECIMAL(5,2),
      -- @D5 DECIMAL(5,2),
      -- @D6 DECIMAL(5,2),
      -- @D7 DECIMAL(5,2))
  AS 
  BEGIN
  
  
  EXEC SP_EXECUTESQL @QUERY
  
  DECLARE CP_DETAILS CURSOR FOR SELECT * FROM #TEMP
  
  OPEN CP_DETAILS
  FETCH NEXT FROM CP_DETAILS INTO     @RESOURCE_NAME,@DAY1,@DAY2,@DAY3,@DAY4,@DAY5,@DAY6,@DAY7,@UTILIZATION
  
  WHILE (@@FETCH_STATUS =0)
  BEGIN
      SET @UTILIZATION = dbo.UTILIZATION(@START_DATE,@END_DATE,@DAY1,                                         @DAY2,@DAY3,@DAY4,@DAY5,@DAY6,@DAY7)
      --INSERT INTO @WEEKLY_REPORT_DETAILS_INFORMATION VALUES(@RESOURCE_NAME,
      --          @DAY1,@DAY2,@DAY3,@DAY4,@DAY5,@DAY6,@DAY7,@UTILIZATION)
      UPDATE #TEMP SET UTILIZATION = @UTILIZATION WHERE RESOURCE_NAME=@RESOURCE_NAME
  
      FETCH NEXT FROM CP_DETAILS INTO @RESOURCE_NAME,@DAY1,@DAY2,@DAY3,@DAY4,@DAY5,@DAY6,@DAY7
  END
  CLOSE CP_DETAILS
  DEALLOCATE CP_DETAILS
  SELECT * FROM #TEMP
  --SELECT DBO.RETRIEVE(@QUERY) AS QUERY FROM CP_DETAILS
  PRINT @QUERY
  DROP TABLE #TEMP
  RETURN 
  END 
  END
  </code></pre>
  
  <p>In middle I use one user-defined function <code>utilization</code>, and passing the parameters as date fields</p>