title: SQL Server Using a condition in a Substring
body: <p>I have a field of data which consists of account numbers like this</p>
  
  <pre><code>16530907-00
  16530907-0001
  
  16589553-00
  16589553-00
  </code></pre>
  
  <p>I want to select everything to the right of the hyphen then if the Length of that substring is >2 I want to Update that field and set it to itself minus the two extra digits on the right.</p>
  
  <p>I am practicing with a select statement</p>
  
  <pre><code>Select SUBSTRING(Account, CHARINDEX('-'), Account)+1, LEN(Account) as test
  FROM Documents
  WHERE SubmissionID=45925 and LEN(test)&gt;2
  </code></pre>
  
  <p>This does not work. What I really want to do is create an update statement that tests the characters to the right of the hyphen if there are more than 2 characters then truncate any extra characters .</p>
  
  <p>Any suggestions would be appreciated.
  Thanks</p>