title: ?ow to write a user defined function in sql to count the number of characters in a given string (back end code of len function)?
body: <p>In C language, we are using the below logic:</p>
  
  <pre><code>const char * z = "testing one two three";
  int m;
  int charcount;
  
  charcount = 0;
  for(m=0; z[m]; m++) {
      if(z[m] != ' ') {
          charcount ++;
      }
  } 
  </code></pre>
  
  <p>How to do it in T-SQL?</p>