您的位置首页生活百科

从数脸事什困许述围远磁知据类型 varchar 转换为 numeric 时出错

问题补充说明:需要用sql server 数据库:某种药库存数量1000库数量100需要计算用数即1000/100=10并根据数序排列库存数量0或者库数量0则数处显示没库存或者未库我用case判断库存数量与库数量都0候做除运算候现数据类型 varchar 转换 numeric 错知道错哪求神指教代码:(注:a.numkcyp.[库存数量]数据类型numeric(18, 5)b.cknumdb_data.[数量]数据类型numeric(18, 5))select a.*,b.*,case when a.num=0 then '库存0能做除' when b.cknum IS null then '取计算数' when a.num<>0 and b.cknum<>0 then cast(a.num as numeric(18, 5))/cast(b.cknum as numeric(18, 5))end as tianshufrom(SELECT ypwc.[名称] as y_name,ypwc.[编号] as bianhao,ypwc.[药品类型] as ytype,ypwc.[规格] as guige,ypwc.[药品单位] as danwei,kcyp.[仓库编号] as cangku,kcyp.[库存数量] as num FROM [T库存药品] as kcyp right join [T药品卫材] as ypwc on kcyp.[药品编号]=ypwc.[编号] where kcyp.[仓库编号]='7' and ypwc.[药品类型]='药') as aleft join (select sum(db_data.[数量]) as cknum,db_data.[编号] as bianhaob from [D调拨单] as db_dan inner join [D调拨数据] as db_data on db_dan.[单据编号]=db_data.[单据编号] where db_dan.[单期]>='2014-03-05 00:00:00' and db_dan.[单期]<='2014-03-05 23:59:59' group by db_data.[编号]) as b on a.bianhao = b.bianhaoborder by tianshu asc

从数脸事什困许述围远磁知据类型 varchar 转换为 numeric 时出错

cast(a.num360问答asnumeric(鸡害18,5))/cast(b.cknumasnumeric(18,5)这个得到的是数值类束妒突源林便棉粮型,而你前面两个得到的是字符类型,我认为只要把这个直接转字符就可以了:

to_char(a.num/b.cknum,$99999.99)