Data Conversion - Convert Decimal to Base n
Date: 9 Aug 2005
A very brute-force but effective and accurate way of converting any decimal number to a string representation in Base n (where n is a number from 10 to 36)
This was developed when SQL 2000 was predominant and SQL 2005 CTEs hadn't been widely adopted, and I'm sure there is a more efficient way of doing this with a CTE. One day I will revisit it, but I've found that the need for it to be very infrequent and usually in a batch job rather than inline SQL, so performance hasn't generally been an issue
Note: There is no bounds checking of the @Base parameter, so unpredictable results will occur if a @Base of greater than 36 is supplied.