SDU Tools: Truncate trailing zeroes in SQL Server T-SQL

Often when I convert a decimal number to a string in T-SQL, I want the simplest version of the number. I really don't want any trailing zeroes (i.e. at the end of the number).

In our free SDU Tools for developers and DBAs, we added a function to do just that: TruncateTrailingZeroes.

The function just takes one parameter: the number to be processed.

You can use our tools as a set or as a great example of how to write functions like these.

Find out more

You can see it in action in the main image above, and in the video here:

Access to SDU Tools is one of the benefits of being an SDU Insider, along with access to our other free tools and eBooks. Please just visit here for more info:

http://sdutools.sqldownunder.com

 

2 thoughts on “SDU Tools: Truncate trailing zeroes in SQL Server T-SQL”

    1. Hi Gerald, Our tools work for all versions from SQL Server 2008 onwards, and customers deploy them across those versions. So we can't (as yet) use TRIM. However, I'm not sure how you'd really use it to turn "12.0" into "12" and still "0.200" into "0.2" and so on. We're aiming to just remove trailing zeroes. (And a decimal point if then trailing). TRIM doesn't give you that option.

Leave a Reply

Your email address will not be published. Required fields are marked *