Error with date insert - Conversion failed when converting date and/or time from character string
<p>I have a stored procedure I am building where it fails when I try to insert data. This is the insert:</p>

<pre><code>INSERT INTO [AdminDB].[dbo].[DEFECTS_MAINTENANCE]([DATE], [Year], [Month], [Total])
    SELECT
        CONVERT(DATE, getdate()) AS 'Date',
        DATENAME(yyyy, getdate()) AS 'Year',
        DATENAME(mm, getdate()) AS 'Month',
        COUNT([BG_BUG_ID]) AS 'Total'
    FROM 
        [maint_maintenance_db].[td].[BUG]
    WHERE
        YEAR(DETECTION_DATE]) = YEAR(getdate()) 
        AND MONTH([DETECTION_DATE]) =  MONTH(getdate())
</code></pre>

<p>When I execute the code above I get this error:</p>

<blockquote>
  <p>Msg 241, Level 16, State 1, Procedure usp_TC_TESTCYCL_ID_COUNT_PILOT_UCPATH, Line 10<br>
  Conversion failed when converting date and/or time from character string.</p>
</blockquote>

<p>When I change the code to use CAST it works, but does not return the values properly. Below is the code:</p>

<pre><code>INSERT INTO [AdminDB].[dbo].[DEFECTS_MAINTENANCE]([DATE], [Year], [Month], [Total])
    SELECT 
        CAST(getdate() AS Date),
        CAST(getdate() AS datetime),
        CAST(getdate() AS datetime), 
        COUNT([BG_BUG_ID]) AS 'Total'
    FROM 
        [maint_maintenance_db].[td].[BUG]
    WHERE
        YEAR(DETECTION_DATE]) = YEAR(getdate()) 
        AND MONTH([DETECTION_DATE]) =  MONTH(getdate())
</code></pre>

<p>How can I get this to work? Any help is appreciated!</p>

<p>Thanks</p>