SQL Server中货币的数据类型是什么?

时间:2021-07-21 16:13:17

What is the data type to the currency value in SQL Server.

SQL Server中货币值的数据类型是什么?

e.g: I want to store $11.23.

e。旅客:我想存11.23美元。

Can I use money type and addtionally will it store the $ symbol?

我可以使用货币类型吗?它会存储$符号吗?

3 个解决方案

#1


0  

answering to the question in the title, the datatype for currency is MONEY.

回答标题中的问题,货币的数据类型是货币。

the money datatype will store the information only, without the format: in your example the information is 11.23 so that's what is saved into the database.

货币数据类型将只存储信息,而没有格式:在您的示例中,信息是11.23,所以这就是保存到数据库中的内容。

the $ sign is part of the format so it will not be stored into the money field.

$符号是格式的一部分,因此不会存储到money字段中。

the usual solution is to have a MONEY field for the amount and a VARCHAR field for the currency symbol/name.

通常的解决方案是为金额设置一个MONEY字段,为货币符号/名称设置一个VARCHAR字段。

#2


4  

DECLARE @Price Decimal(18,2) = 11.23
SELECT FORMAT(@Price,'c','en-US') AS 'CURRENCY IN US Culture'

#3


1  

I think the best way to store the currency is to use either NUMERIC or DECIMAL data types as these values participates in calculations. If we use NVARCHAR to allow the storage with symbol like ($), it will cost extra during calculations when use in WHERE clause. We can choose the precision and scale accordingly.

我认为存储货币的最好方法是使用数字或十进制数据类型,因为这些值参与计算。如果我们使用NVARCHAR来允许存储有象($)这样的符号,那么当在WHERE子句中使用时,它将花费额外的时间。我们可以选择相应的精度和刻度。

#1


0  

answering to the question in the title, the datatype for currency is MONEY.

回答标题中的问题,货币的数据类型是货币。

the money datatype will store the information only, without the format: in your example the information is 11.23 so that's what is saved into the database.

货币数据类型将只存储信息,而没有格式:在您的示例中,信息是11.23,所以这就是保存到数据库中的内容。

the $ sign is part of the format so it will not be stored into the money field.

$符号是格式的一部分,因此不会存储到money字段中。

the usual solution is to have a MONEY field for the amount and a VARCHAR field for the currency symbol/name.

通常的解决方案是为金额设置一个MONEY字段,为货币符号/名称设置一个VARCHAR字段。

#2


4  

DECLARE @Price Decimal(18,2) = 11.23
SELECT FORMAT(@Price,'c','en-US') AS 'CURRENCY IN US Culture'

#3


1  

I think the best way to store the currency is to use either NUMERIC or DECIMAL data types as these values participates in calculations. If we use NVARCHAR to allow the storage with symbol like ($), it will cost extra during calculations when use in WHERE clause. We can choose the precision and scale accordingly.

我认为存储货币的最好方法是使用数字或十进制数据类型,因为这些值参与计算。如果我们使用NVARCHAR来允许存储有象($)这样的符号,那么当在WHERE子句中使用时,它将花费额外的时间。我们可以选择相应的精度和刻度。