The key idea is that the output needs to be converted to a string to put 0
s in front. If you don't like typing out long strings of 0s, you can use str()
and replace()
:
SELECT TOP 1 REPLACE(STR(G.ACCOUNTINGCURRENCYAMOUNT, 15, 2), ' ', '0')
FROM MicrosoftDynamicsAx.dbo.GENERALJOURNALACCOUNTENTRY G;
EDIT:
To handle negative numbers . . .
SELECT TOP 1 (CASE WHEN G.ACCOUNTINGCURRENCYAMOUNT >= 0
THEN REPLACE(STR(G.ACCOUNTINGCURRENCYAMOUNT, 15, 2), ' ', '0')
THEN '-' + REPLACE(STR(ABS(G.ACCOUNTINGCURRENCYAMOUNT), 14, 2), ' ', '0')
END)
FROM MicrosoftDynamicsAx.dbo.GENERALJOURNALACCOUNTENTRY G;