As part of the blog series TSQL - Solve it YOUR Way, today we will tackle a numeric parsing question. While past topics include solutions that vary from 15-150 lines of TSQL code, all of today's solutions will be very short. A question was recently posted in the MSDN forums asking how to retrieve the digits after the decimal for a numeric data type. Off the top of our heads, many people can probably come up with a few solutions. After sending the question out to the blog series contributors, we came up with ten solutions that highlight creative parsing solutions and some less known tips and tricks within T-SQL.
Topic: Given a numeric value, return the digits after the decimal (ex: 3.142 returns 142)
It is very common to encounter situations where parsing is required in some capacity. The solutions presented above cover common parsing techniques such as SUBSTRING and PARSENAME, but also leverage other constructs such as STUFF, REVERSE, Modulo, and others in creative ways. I hope that you are able to learn a lot by trying out the problem yourself and then reading through the additional solutions.
Special thanks to Tom, Olaf, Jingyang, Steven, and Kent for their valuable forums contribution and for contributing to this series!
Hope that helps,Sam Lester (MSFT)