Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Format decimal value to fraction using a tally table.

By Adrian Facio,

This function takes a decimal value and returns fractional representation of this value.

SELECT dbo.DecimalToFraction(12.5) 

Result: 12 1/2

The interesting thing about this code is that it uses a tally table to find the smallest denominator for the decimal part.

Total article views: 933 | Views in the last 30 days: 1