SQL 如何在 SELECT 语句中格式化我的货币和十进制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9312040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How Do I Format My Currency and Decimal in a SELECT Statement
提问by jcervantes
I have a SQL select statement that doesnt want to format my $ values correctly. The $ ammount returned should be 95,399,927.38 instead I get 9,539,927,385.00 I tried DECIMAL() a few different ways. What Am I missing? My info on the field is below.
我有一个 SQL select 语句不想正确格式化我的 $ 值。返回的 $ ammount 应该是 95,399,927.38 而我得到 9,539,927,385.00 我尝试了 DECIMAL() 几种不同的方法。我错过了什么?我在该领域的信息如下。
In the past I just formatted it in Excel when I pulled in my data but this one isnt going to be in Excel.
过去,当我提取数据时,我只是在 Excel 中对其进行了格式化,但这不会在 Excel 中。
COLUMN_NAME SXAS01
DATA_TYPE 3
TYPE_NAME DECIMAL
COLUMN_SIZE 15
BUFFER_LENGTH 17
DECIMAL_DIGITS 0
NUM_PREC_RADIX 10
NULLABLE 0
REMARKS (null)
COLUMN_DEF 0
SQL_DATA_TYPE 3
SQL_DATETIME_SUB (null)
CHAR_OCTET_LENGTH (null)
ORDINAL_POSITION 11
IS_NULLABLE NO
Formatted it perfectly. select decimal(SXAS01,9,2)
完美地格式化了它。选择十进制(SXAS01,9,2)
回答by Marc
Is it sql server? You could try
是sql server吗?你可以试试
SELECT CONVERT(Decimal(9,2), SXAS01)
Or
或者
select CAST(SXAS01 AS decimal(10,1))
DB2 You can try
DB2 你可以试试
select decimal(SXAS01,9,2)
OR
或者
select DEC(SXAS01,9,2)