sql中的算术运算

时间:2013-01-04 05:08:51

标签: sql-server sql-server-2008

第一个算术功能工作

select CreditLimit,'sum'=CreditLimit+Zip from Customers

select CreditLimit,'sub'=CreditLimit-Zip from Customers

select CreditLimit,'div'=CreditLimit/Zip from Customers

最后两个合成功能或不工作显示错误

select CreditLimit,'mod'=CreditLimit%Zip from Customers

ERROR DISPALY: Arithmetic overflow error converting expression to data type smallmoney.

select CreditLimit,'mul'=CreditLimit*Zip from Customers

ERROR DISPALY:The data types smallmoney and nchar are incompatible in the modulo operator.

预先感谢朋友们!

1 个答案:

答案 0 :(得分:0)

我怀疑列ZIPnchar数据类型。在执行算术运算之前,您需要将其转换为smallmoney

select CreditLimit,'mod'=CreditLimit%convert(smallmoney,Zip) from Customers