title: Substring (...,...,CHARINDEX(....)-0.5) function
body: <p>I have this string in a column called <code>Parent_ID</code>. Example of the strings that exist there: </p>
  
  <pre><code>RBIA-3340-CU-XM-01-D/RBIA-3340-01-4-D-34080-11441A1-2TC-001/B1
  </code></pre>
  
  <p>what I want is to get:</p>
  
  <pre><code>RBIA-3340-CU-XM-01-D/RBIA-3340-01-4-D-34080-11441A1-2TC-001
  </code></pre>
  
  <p>without <code>/B1</code></p>
  
  <p>When I wrote this code:</p>
  
  <pre><code>SELECT Substring([parent_id], 1,
                   CHARINDEX('/B',parent_id,25)-1)
  FROM [c3d_aug].[dbo].[atta_properties]
  </code></pre>
  
  <p>I got this error:</p>
  
  <blockquote>
    <p>"Msg 537, Level 16, State 3, Line 1 Invalid length parameter passed to
    the LEFT or SUBSTRING function."</p>
  </blockquote>
  
  <p>After testing I accidentally changed <code>-1</code> to <code>-0.5</code> it worked fine.</p>
  
  <pre><code>SELECT Substring([parent_id],1,
                   CHARINDEX('/B',parent_id,25)-0.5)
  FROM [c3d_aug].[dbo].[atta_properties]
  </code></pre>
  
  <p>Can someone explain why ?! please, note that main string given above does not contain any spaces.</p>