t-sql Different datatype possible in a case?
<p>I have this query</p>

<pre><code>SELECT
CASE WHEN dbo.CFE_PPHY.P77 IS NOT NULL OR dbo.CFE_PPHY.P77 &lt;&gt;'' 
       THEN MONTH(dbo.CFE_PPHY.P77)
     WHEN dbo.CFE_PPHY.P70 IS NOT NULL OR dbo.CFE_PPHY.P70 &lt;&gt;'' 
       THEN MONTH(dbo.CFE_SERVICE_EVTS.C10_2)
     ELSE COALESCE(CONVERT(VARCHAR,dbo.CFE_PPHY.P77)+
          CONVERT(VARCHAR,dbo.CFE_SERVICE_EVTS.C10_2),'toto') END 
 AS CFELiasse_DateEffetEIRL_MM_N
FROM CFE_PPHY LEFT JOIN CFE_SERVICE_EVTS ON CFE_PPHY.colA = CFE_SERVICE_EVTS.colB
</code></pre>

<p>The <code>ELSE</code> part is giving me headaches.</p>

<p>The columns <code>CFE_PPHY.P77</code> and <code>CFE_SERVICE_EVTS.C10_2</code> have date time format. I'm turning them into varchar. Yet when I'm running the query, I have the following error</p>

<blockquote>
  <p>Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value 'toto' to data type int.</p>
</blockquote>

<p>Obviously, I cannot turn <code>toto</code> to an integer. Fair enough. However, from my point of view, I've converted the datetime format to a varchar format, so it should do the work.</p>

<p>Where am I wrong?</p>

<p>Thanks</p>