Existe uma função, Util_ToWords , na versão gratuita do SQL# Biblioteca SQLCLR que escrevi que faz isso (bem, sem as palavras "dólar (s)" e "centavos" adicionadas):
SELECT SQL#.Util_ToWords(10); -- Ten
SELECT SQL#.Util_ToWords(100); -- One Hundred
SELECT SQL#.Util_ToWords(1000); -- One Thousand
SELECT SQL#.Util_ToWords(120.20); -- One Hundred Twenty and 20
SELECT SQL#.Util_ToWords(212); -- Two Hundred Twelve
SELECT SQL#.Util_ToWords(123097.4);-- One Hundred Twenty Three Thousand, Ninety Seven and 40
O exemplo a seguir injeta as palavras "dollar(s)" e "cents" no valor de retorno (que foi originalmente destinado à impressão em cheques):
DECLARE @Amount MONEY = 2.08;
;WITH cte AS
(
SELECT N' dollar' + CASE WHEN @Amount >= 1.00 AND @Amount < 2.00 THEN N''
ELSE N's'
END AS [Currency],
SQL#.Util_ToWords(@Amount) AS [Words]
)
SELECT CASE CHARINDEX(N' and ', cte.[Words])
WHEN 0 THEN cte.[Words] + cte.[Currency]
ELSE STUFF(cte.[Words], CHARINDEX(N' and ', cte.[Words]), 0, cte.[Currency])
+ N' cents'
END
FROM cte;
Devoluções:
Two dollars and 08 cents