如何在T-SQL中乘以大数字 [英] How to multiply big numbers in the T-SQL
本文介绍了如何在T-SQL中乘以大数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在sql中有这个代码:
I have this code in sql:
SELECT Count * Cost AS CountOfAll
FROM [Plan.Tools]
计数=工具数量。
成本=每种工具的成本。
当执行此代码时,我有一个错误。
因为我使用成本,并且有溢出。与运行此代码类似:
Count = Number of tools.
Cost = The cost of each tools.
when In execute this code I have an error.
because I work with cost, and has overflow. Like running this code:
SELECT 1234*12342222 AS Res
我使用CAST但不是很好。
我想要乘以大数字。我该怎么办?
I use CAST but not good.
I want to multiply the big numbers. what can I do?
推荐答案
现在已经复制了你的问题。尝试以下作为解决方案
Have now reproduced your problem. Try the following as a solution
SELECT (convert(decimal(15,5), [Count]) * convert(decimal(15,5), Cost)) AS CountOfAll from [Plan.tools]
如果仍然出现溢出,请尝试将 decimal(15,5)
更改为十进制(20,5)
在你的第二个例子中强制数字的类型如此
On your second example force the type of the numbers like so
SELECT 1234.0 * 12342222.0 AS Res
第一位计数 是一个保留字......尝试用方括号围绕它[计数]
On your first bit "Count" is a reserved word ... try surrounding it with square brackets [Count]
这篇关于如何在T-SQL中乘以大数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文