使用批量插入时,我在 money 列中的值发生了变化
My values in money column are changed when bulk insert is used
我有一个 table 存储金额的地方。当我曾经将这些值从 table 插入到另一个 table 时;价值观改变。
在我的第一个 table 中,列 'PRICE' 的值是 130,但是当使用批量插入时,它在另一个 table 中被插入为 129.60。
我的批量插入命令是:
Insert into InvoiceDetail(InvoiceId,AgentId,ProductCode,BrandId,Qty,Price,ProductType)
Select SCOPE_IDENTITY(),'12736387',ProductCode,BrandId,Qty,M2CPrice,ProductType from
UserPackages where AgentId='12736387'
我建议您使用 decimal/numeric
而不是 money
,因为货币不精确。您可以查看 Should you choose the MONEY or DECIMAL(x,y) datatypes in SQL Server?
请注意 MONEY
数据类型存在舍入误差。性能明智的小数也更好。查看 Aaron Bertrand 的博客:Performance / Storage Comparisons : MONEY vs. DECIMAL
我有一个 table 存储金额的地方。当我曾经将这些值从 table 插入到另一个 table 时;价值观改变。
在我的第一个 table 中,列 'PRICE' 的值是 130,但是当使用批量插入时,它在另一个 table 中被插入为 129.60。
我的批量插入命令是:
Insert into InvoiceDetail(InvoiceId,AgentId,ProductCode,BrandId,Qty,Price,ProductType)
Select SCOPE_IDENTITY(),'12736387',ProductCode,BrandId,Qty,M2CPrice,ProductType from
UserPackages where AgentId='12736387'
我建议您使用 decimal/numeric
而不是 money
,因为货币不精确。您可以查看 Should you choose the MONEY or DECIMAL(x,y) datatypes in SQL Server?
请注意 MONEY
数据类型存在舍入误差。性能明智的小数也更好。查看 Aaron Bertrand 的博客:Performance / Storage Comparisons : MONEY vs. DECIMAL