title: SQL computed column - formula to calculate length and do a substring
body: <p>Hi I'm looking for a easier solution to one of the columns in SQL table. The column has a datatype of nvarchar(50). However, I want to put a formula in the <strong>computed column</strong> field of this column whereby:</p>
  
  <ul>
  <li><p>check if the length of the data being inserted is more than 50.</p></li>
  <li><p>If it is, then take the first 36 characters.</p></li>
  <li>create the string - "<strong>[SQL-Truncated]…</strong>"+"<strong>the 34 characters from previous step</strong>" ([SQL-Truncated]... is 16 characters in length.)</li>
  <li>insert this new string in that column instead, thereby ensuring we only get 50 chars.</li>
  </ul>