title: Convert DateTIme to Date / "int is not allowed" error
body: <p>I've searched and searched - found variations on the theme, but no real answer to my problem.</p>
  
  <p>I need to convert the <code>MAX</code> of a <code>datetime</code> to <code>date</code>, and insert it into a new table I've created.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>INSERT INTO [dbo].[OptOutEmails]([emailaddressid],[FirstOptOutDate], [LastOptOutDate], [bu_id], [brand_id])
  SELECT [dbo].[DistinctEmailIds].[emailaddressid] as email
  ,[dbo].[emailaddresses_summary].[bu_id]
  ,[dbo].[emailaddresses_summary].[brand_id]
  , CONVERT(datetime, max([emailaddresses_summary].[FirstOptOutDate])) AS FirstOptOutDate
  , CONVERT(datetime, max([emailaddresses_summary].[LastOptOutDate])) AS LastOptOutDate
  FROM [dbo].[DistinctEmailIds] 
  JOIN [dbo].[emailaddresses_summary] 
  ON [dbo].[DistinctEmailIds].[emailaddressid] = [dbo].[emailaddresses_summary].[emailaddressid]
  WHERE [dbo].[emailaddresses_summary].[LastOptOutDate] IS NOT NULL
  GROUP BY [dbo].[DistinctEmailIds].[emailaddressid],[dbo].[emailaddresses_summary].[bu_id],[dbo].[emailaddresses_summary].[brand_id];
  GO
  </code></pre>
  
  <p>It needs to go into this table:</p>
  
  <pre><code>[emailaddressid] int not null PRIMARY KEY
  , [FirstOptOutDate] datetime null
  , [LastOptOutDate] datetime null
  , [bu_id] int null
  , [brand_id] int null
  </code></pre>
  
  <p>The error message I get: Msg 257, Level 16, State 3, Line 56</p>
  
  <blockquote>
    <p>Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query.</p>
  </blockquote>
  
  <p>I've tried everything I can think of. The resultant <code>CONVERT</code> statement in my code is from a string I thought would resolve this. Nothing is working. Please help?</p>