title: Removing leading zeros in a string in sqlserver
body: <p>I want to remove leading zeros for a varchar column. Actually we are storing version information in a column. Find below example versions.</p>
  
  <p>2.00.001<br>
  The output would be : 2.0.1  </p>
  
  <p>Input : 2.00.00.001<br>
  The output would be: 2.0.0.1  </p>
  
  <p>Input : 2.00<br>
  The output would be : 2.0</p>
  
  <p>The dots in the version column not constant.  It may be two or three or four</p>
  
  <p>I found some solutions in google but those are not working. Find below are the queries I tried.</p>
  
  <pre><code>SELECT SUBSTRING('2.00.001', PATINDEX('%[^0 ]%', '2.00.001' + ' '), LEN('2.00.001'))
  
  SELECT REPLACE(LTRIM(REPLACE('2.00.001', '0', ' ')),' ', '0')
  </code></pre>
  
  <p>Please suggest me the best approach in sqlserver.</p>