SQL Server Money数据类型问题
我们有带有货币数据类型列的 SQL Server 2000 数据库,并且我们在货币列中的数字方面遇到了奇怪的问题,在这些列中我们存储了带有 2 位小数的数字。很长一段时间一切都很好。但现在我看到在某些行中,数字 47.22 现在是数字 47.2178。当我选择 CAST(COLUMN as CHAR) 时,结果是 47.22,但是当我从 ADO 记录集中检索值时,结果是 47.2178。我浏览所有应用程序,如果有任何地方可以写入小数点后 4 位的数字,但什么也没找到(并且在应用程序历史日志中,有应用程序将 47.22 写入数据库的记录)。这可能是 SQL Server 的问题吗?
编辑:应用程序是用VB6编写的
We have SQL Server 2000 database with money data type columns and we have strange problem with numbers within money columns in which we store numbers with 2 decimal places. For o long time everything was OK. But now I see that in some rows where was number 47.22 is now number 47.2178. When i select CAST(COLUMN as CHAR) result is 47.22 but when i retrieve value from ADO recordset i have result 47.2178. I browse all application if there is any place where it can write number with 4 decimal places and find nothing(and in application history log there are records that application writes 47.22 to database). Can it be some SQL Server problem?
edit:application is written in VB6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您实际上使用的是货币数据类型还是浮点类型?
当您使用企业管理器从该表中进行选择时会发生什么?一切看起来都还好吗?
我的猜测是,您正在将数据转换为浮点类型。可能在 ADO 代码中。
更新
每 MS:当将钱铸造为字符串类型时,机器的区域设置开始发挥作用。这就是为什么它四舍五入到小数点后两位。
你有三个选择。
Are you actually using the money data type or are you using a floating point type?
What happens when you use enterprise manager to select from that table? Does everything look ok?
My guess is that you are converting the data to a floating point type somewhere along the way. Probably in the ADO code.
UPDATE
Per MS: When casting money to a string type, the machine's locale comes into play. Which is why it is rounded to 2 decimal places.
You have three options.
不要使用企业管理器对表中实际存储的内容得出任何结论。 EM 有时对如何解释数据有自己的看法。
查看您的 CAST(....to CHAR) 原因在文档中进行了解释(查找 CAST & CONVERT)...
编辑:终于弄清楚如何使用 BlockQuote 功能。 :-)
Don't use Enterprise Manager to draw any conclusions on what is really stored in your tables. EM has sometimes its own opinion on how to interpret data.
Looking at your CAST(....to CHAR) the reason is explained in the documentation (look for CAST & CONVERT)...
EDIT: Finally figured out how to use the BlockQuote feature. :-)