title: Send by mail a query result with a job in SQL Server
body: <p>I'm trying to send an email by a SQL Server job with the result of a query.</p>
  
  <p>The query works perfectly and I face an issue when I pass a TABLE in the <code>@query</code> parameter of <code>sp_send_dbmail</code></p>
  
  <p>Here is my code : </p>
  
  <pre><code>DECLARE @res TABLE 
  (
    SiteCode [nvarchar](50), 
    DateLastODV [datetime]
  );
  
  INSERT INTO @res
  SELECT
        SiteCode
        ,MAX(DateODV) AS DateLastODV
    FROM Configuration.ODVCompteur
    where year(DateODV) = 2015
    group by SiteCode
    order by DateLastODV desc
  
  EXEC  msdb.dbo.sp_send_dbmail
        @profile_name = 'Foo',
        @recipients = 'foo@foooo.com', 
        @subject = 'Foooooooo',
        @query = @res,      
        @Attach_Query_result_as_file = 0
  </code></pre>
  
  <p>I got this error (in french but can easily be translate if needed) : </p>
  
  <blockquote>
    <p>Line 0: Procedure: sp_send_dbmail, Msg 206, Level 16, State 2: Conflit
    de types d'opérandes : table est incompatible avec nvarchar(max)</p>
  </blockquote>