title: Invalid length parameter passed to the LEFT or SUBSTRING function
body: <p>I've seen a few of these questions asked but haven't spotted one that's helped!! I'm trying to select the first part of a postcode only, essentially ignoring anything after the space. the code i am using is</p>
  
  <pre><code>SUBSTRING(PostCode, 1 , CHARINDEX(' ', PostCode ) -1)
  </code></pre>
  
  <p>However, I am getting Invalid length parameter passed to the LEFT or SUBSTRING function! There's no nulls or blanks but there are some the only have the first part. Is this what causing the error and if so what's the work around?</p>