title: unable to set variable consistantly
body: <p>I am unable to to consistently set and query a variable @imgpath
  After getting the value from it, i see it is not consistant
  With when <code>left(SUBSTRING_INDEX(SUBSTRING_INDEX(pa.name, ' ', 2), ' ', -1),1) in("C")</code></p>
  
  <p>for instance, the concat returns a "0" under this section
  The parsed data from <code>SUBSTRING_INDEX(SUBSTRING_INDEX(pa.name, ' ', 2), ' ', -1)</code>
  looks like this:</p>
  
  <pre><code>C5
  C178
  </code></pre>
  
  <p>Further down in my script, I query @image path like</p>
  
  <pre><code>If(substring(@imgpath,1,1) = "C",dosmthing,dosomthing)
  </code></pre>
  
  <p>Many times this will return "0"</p>
  
  <p>I think it is either how or where I am setting @imgpath</p>
  
  <p>If I don't assign it to a variable using THEN, it works normally (correctly)</p>
  
  <pre><code>select pa.name,
  case
    when left(SUBSTRING_INDEX(SUBSTRING_INDEX(pa.name, ' ', 2), ' ', -1),1) in("B") then  @imgpath :=
      if(SUBSTRING_INDEX(SUBSTRING_INDEX(pa.name, ' ', 2), ' ', -1) &lt; "B16",3464,101)
    when left(SUBSTRING_INDEX(SUBSTRING_INDEX(pa.name, ' ', 2), ' ', -1),1) in("C") then @imgpath :=
       if(length(SUBSTRING_INDEX(SUBSTRING_INDEX(pa.name, ' ', 2), ' ', -1)) &lt; 3,
         concat(left(SUBSTRING_INDEX(SUBSTRING_INDEX(pa.name, ' ', 2), ' ', -1),1), "0", 
                right(SUBSTRING_INDEX(SUBSTRING_INDEX(pa.name, ' ', 2), ' ', -1),1)),SUBSTRING_INDEX(SUBSTRING_INDEX(pa.name, ' ', 2), ' ', -1))
    when left(SUBSTRING_INDEX(SUBSTRING_INDEX(pa.name, ' ', 2), ' ', -1),1) = "J" then @imgpath :=
      if(SUBSTRING_INDEX(SUBSTRING_INDEX(pa.name, ' ', 2), ' ', -1) &lt; "J19",3464,101)
    when left(SUBSTRING_INDEX(SUBSTRING_INDEX(pa.name, ' ', 2), ' ', -1),1) = "O" then @imgpath := 101
    when SUBSTRING_INDEX(SUBSTRING_INDEX(pa.name, ' ', 2), ' ', -1) &lt; 116 then @imgpath := 3464
    when SUBSTRING_INDEX(SUBSTRING_INDEX(pa.name, ' ', 2), ' ', -1) &gt;= 116 then @imgpath := 101
   end as "temp",
  </code></pre>