What's the simple way to add the dollar sign ('$') or currency to a decimal data type on the following query:
SELECT TOP 100000
SUM ([dbo].[Entry].[Amount]) AS 'Total Charges'
Thanks for the help!
Use the CAST() function to convert an integer to a DECIMAL data type. This function takes an expression or a column name as the argument, followed by the keyword AS and the new data type. In our example, we converted an integer (12) to a decimal value (12.00).
The T-SQL language offers two functions to convert data from one data type to a target data type: CAST and CONVERT. In many ways, they both do the exact same thing in a SELECT statement or stored procedure, but the SQL Server CONVERT function has an extra parameter to express style.
This is just presenting concern and should be done in application layer.
But SQL Server
can do it using FORMAT
function:
SELECT FORMAT(SUM ([Amount]), 'c', 'en-US') AS 'Total Charges'
FROM Entry
LiveDemo
Output:
╔═════════════════╗
║ Total Charges ║
╠═════════════════╣
║ $21.00 ║
╚═════════════════╝
Here is an example using Sql Server 2012
Declare @Currency float = 1500.00
Select Format(@Currency, 'C', 'en-US')
https://msdn.microsoft.com/pt-br/library/hh213505(v=sql.110).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With