title: SSRS Expression - #Error in an obviously correct expression
body: <p>I have an SSRS expression with this in it:</p>
  
  <pre><code>=IIF(
      Fields!CUT.Value.ToString().Length &gt; 1
      ,IIF(
          Fields!CUT.Value.ToString().Contains(","), 
          Fields!CUT.Value.ToString().Substring(0, Fields!CUT.Value.ToString().IndexOf(",")),
          Fields!CUT.Value.ToString()
      )
      ,""
  )
  </code></pre>
  
  <p><strong>Translation:</strong><br>
  If the field contains a <code>,</code>, Get me the <code>substring</code> of the field from the first position to where the <code>,</code> is. If the field does not contain <code>,</code>, just get me the entire field.</p>
  
  <p><strong>Probelm:</strong><br>
  I get a <code>#Error</code> in all the pages where there is NO COMMA. If there is a COMMA, it works as expected. One of the fields, the value is <code>4</code>. In a different scenario, the value is <code>17/64" Corrugated</code>. I get an error for both of those.</p>
  
  <p><strong>What I've tried:</strong><br>
  I've tried a few different approaches:</p>
  
  <ol>
  <li><p>Used <code>LIKE</code> instead of <code>Contains</code>    </p>
  
  <pre><code>=IIF(
      IsNothing(Fields!CUT.Value)
      ,""
      ,IIF(
          Fields!CUT.Value LIKE "*,*", 
          Mid(Fields!CUT.Value, InStr(Fields!CUT.Value, ",") + 1,  (LEN(Fields!CUT.Value) - InStr(Fields!CUT.Value, ",") - 1))
          Fields!CUT.Value
      )
  )
  </code></pre></li>
  <li><p>I added a new field to my <code>dataset</code> that replaces <code>,</code> with <code>XXXX</code>. I thought, maybe SSRS is not able to understand that I am talking about a <code>,</code> as a part of the string. And then changed the query to see if there is an <code>XXXX</code> in it. Still got the same <code>#Error</code></p></li>
  <li><p>Delete the <code>.data</code> file, cleaned the project, and rebuilt the project. Because, this is so obviously not incorrect. So I thought maybe it is not looking at the latest version of the report.</p></li>
  </ol>
  
  <p>Nothing seems to do it! I am really close to doing something bad! This thing is driving me insane.</p>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li>Anyone see anything wrong with either of my expressions?</li>
  <li>Is there a better way to do to what I am trying to accomplish? If there is a <code>,</code>, give me everything before the <code>,</code>. If not, give me everything.</li>
  </ol>
  
  <p><strong>Edit 1:</strong><br>
  Worth noting that, in a different field, I am doing something very similar to this:</p>
  
  <pre><code>IIF(
      IsNothing(Fields!CUT.Value)
      ,""
      ,IIF(
          Fields!CUT.Value LIKE "*,*"
          ," | Length: " &amp; Mid(Fields!CUT.Value, InStr(Fields!CUT.Value, ",") + 1,  (LEN(Fields!CUT.Value) - InStr(Fields!CUT.Value, ",") - 1))
          ,""
      )
  )
  </code></pre>
  
  <p>What this is doing is, if there is a <code>,</code> in that very same field, get me everything AFTER the <code>,</code> and append it to <code>| Length:</code>. If there is no <code>,</code>, just show an empty space <code>""</code>. This works perfectly fine. In situations where there is a <code>,</code> and where there is NO <code>,</code>. So I've concluded that Microsoft is using SSRS to make me go crazy. </p>