这个语句总是报错:Arithmetic overflow error converting varchar to data type numeric.

feihongtao 2007-05-11 06:12:18
declare @li_days decimal(4,0),
@table_name char(12),
@user_code char(9)
EXEC('update '+@table_name+'
set gz_sbxz=(case
when salary_type=''C'' then cast((low_salary+gz_zgjt+gz_jsjt+gz_zwjt+gz_tzx)*day_number as decimal(4,0))
when salary_type=''B'' then cast((low_salary+gz_zgjt+gz_jsjt+gz_zwjt+gz_tzx) as decimal(4,0))
else
cast((low_salary+gz_zgjt+gz_jsjt+gz_zwjt+gz_tzx)*day_number/'''+@li_days+''' as decimal(4,0))
end)
from set_right_dept_dbf
where set_right_dept_dbf.dept_code='+@table_name+'.dept_code and
set_right_dept_dbf.if_enabled=''T'' and
set_right_dept_dbf.work_code='''+@user_code+''' ')
...全文
1691 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
feihongtao 2007-05-11
  • 打赏
  • 举报
回复
换成''+@li_days+''后,输出的是下面的结果,@li_days根本没接收传进去的参数。
update salary200704
set gz_sbxz=(case
when salary_type='C' then cast((low_salary+gz_zgjt+gz_jsjt+gz_zwjt+gz_tzx)*day_number as decimal(4,0))
when salary_type='B' then cast((low_salary+gz_zgjt+gz_jsjt+gz_zwjt+gz_tzx) as decimal(4,0))
else
cast((low_salary+gz_zgjt+gz_jsjt+gz_zwjt+gz_tzx)*day_number/'+@li_days+' as decimal(4,0))
end)
from set_right_dept_dbf
where set_right_dept_dbf.dept_code=salary200704.dept_code and
set_right_dept_dbf.if_enabled='T' and
set_right_dept_dbf.work_code='200473552'
feihongtao 2007-05-11
  • 打赏
  • 举报
回复
问题是出在这里:'''+@li_days+'''
如果我换成'+@li_days+',还是报同样的错误:
Arithmetic overflow error converting varchar to data type numeric.

34,873

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧