Function To trim Leading and trailing characters from string in sql server


This is Scalar Function To trim Leading and trailing characters from string in SQL Server. As there is no in built function in sql server for the same. Using this one can trim leading/trailing any character(s) from string .

As there is no In-built function in sql server to trim leading characters or trailing characters or both from a string in SQL server. This scalar function will help in doing the same.It takes two parameters:

  • Input string
  • Character to trim
Code-example:Following code-snippet defined it.
Select dbo.fn_RemoveLeadingTrailingChar(',1,2,3,4,5,,,',',')
Output will be:
1,2,3,4,5
It will trim n number of occurrences of the characters that you want to trim in beginning or end of the string.It is well tested . Passing the null or empty string does not throw any error.


Attachments

  • TrimleadingTrailingChar (46449-1-TrimleadingTrailingChar.sql.txt)
  • Comments

    No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: