title: Conversion failed when converting the varchar value in case statement
body: <p>I cant not get my head around it. We have following simple query.</p>
  
  <pre><code>DECLARE @bFlag bit
  SET @bFlag = 0
  SELECT  something = CASE
                  WHEN @bFlag = 1 THEN
                      CASE
                          WHEN RS.intInterval = 1 THEN '"Days"'
                          WHEN RS.intInterval = 2 THEN '"Weeks"'
                          WHEN RS.intInterval = 3 THEN '"Months"'
                          WHEN RS.intInterval = 4 THEN '"Years"'
                      END
                  Else 
                      RS.intInterval
                  End
  from    MyTable  AS RS WITH (NOLOCK)
  </code></pre>
  
  <p>So I want to get <code>intInterval</code>(which is <code>int</code>) if <code>flag</code> is not set to <code>true</code>. Otherwise if <code>flag</code> is set to <code>true</code>, I want to get <code>Days</code>, <code>Weeks</code>, etc depending upon value of <code>intInterval</code>. If I run this with <code>@bFalg = 1</code>, I get this error:</p>
  
  <blockquote>
    <p>Conversion failed when converting the varchar value '"Weeks"' to data
    type int</p>
  </blockquote>
  
  <p>which does not make any sense as I am not converting anything.</p>
  
  <p>I know I can fix it by putting <code>cast (intInterval as varchar)</code> in <code>else</code> part. However I want to know the reason why I am getting this error, why <code>case</code> is trying to convert 'Weeks' to <code>int</code>?</p>