qq_31100265 2016-03-04 02:27 采纳率: 0%
浏览 1572
已结题

SQL数据抽取,出现数据类型转换错误,求大神帮忙看一下。

select a.patient_id+'_'+cast(a.item_no as varchar(20))+'_'+cast(a.ledger_sn as varchar(20)) pk_pay,null pk_dcpv,null pvcode,'SDDYRMYY_G' code_group,'SDDYRMYY' code_org ,
cheque_type code_pay_mode,b.name name_pay_mode,a.charge amount,convert(varchar,a.dcount_date,120) date_pay, 'O' code_pvtype,
case when a.charge>=0 then 5 when a.charge<0 then 2 end dt_paytype,a.dcount_id code_psn_pay,psn.name name_psn_pay,mz_dept_no code_dept_pay
from mz_deposit_b a
left join zd_cheque_type b on a.cheque_type = b.code
left join a_employee_mi psn on psn.code = a.dcount_id
--WHERE a.dcount_date between ${BEGIN_DATE} and ${END_DATE}

where EXISTS
(
select patient_id,times
from uh_dc_pi_temp t
where t.patient_id=a.patient_id
)
union all
select a.patient_id+'_'+cast(a.item_no as varchar(20))+'_'+cast(a.ledger_sn as varchar(20)) pk_pay,'O' code_pvtype,
a.patient_id+'_'+convert(varchar,times) pk_dcpv,a.patient_id+convert(varchar,times) pvcode,'SDDYRMYY_G' code_group,'SDDYRMYY' code_org ,
cheque_type code_pay_mode,b.name name_pay_mode,a.charge amount,convert(varchar,a.price_date,120) date_pay,
1 dt_paytype,a.price_opera code_psn_pay,psn.name name_psn_pay,mz_dept_no code_dept_pay
from gh_deposit_b a
left join zd_cheque_type b on a.cheque_type = b.code
left join a_employee_mi psn on psn.code = a.price_opera
--WHERE price_date between ${BEGIN_DATE} and ${END_DATE}
where EXISTS
(
select patient_id,times
from uh_dc_pi_temp t
where t.patient_id=a.patient_id
)

union all

select a.patient_id+'_'+cast(a.item_no as varchar(20))+'_'+cast(a.ledger_sn as varchar(20)) pk_pay,null pk_dcpv,null pvcode,'SDDYRMYY_G' code_group,'SDDYRMYY' code_org ,
cheque_type code_pay_mode,b.name name_pay_mode,a.charge amount,convert(varchar,a.dcount_date,120) date_pay, 'O' code_pvtype,
case when a.charge>=0 then 5 when a.charge<0 then 2 end dt_paytype,a.dcount_id code_psn_pay,psn.name name_psn_pay,mz_dept_no code_dept_pay
from mz_deposit_c a
left join zd_cheque_type b on a.cheque_type = b.code
left join a_employee_mi psn on psn.code = a.dcount_id
--WHERE a.dcount_date between ${BEGIN_DATE} and ${END_DATE}

where EXISTS
(
select patient_id,times
from uh_dc_pi_temp t
where t.patient_id=a.patient_id
)
union all
select a.patient_id+'_'+cast(a.item_no as varchar(20))+'_'+cast(a.ledger_sn as varchar(20)) pk_pay,'O' code_pvtype,
a.patient_id+'_'+convert(varchar,times) pk_dcpv,a.patient_id+convert(varchar,times) pvcode,'SDDYRMYY_G' code_group,'SDDYRMYY' code_org ,
cheque_type code_pay_mode,b.name name_pay_mode,a.charge amount,convert(varchar,a.price_date,120) date_pay,
1 dt_paytype,a.price_opera code_psn_pay,psn.name name_psn_pay,mz_dept_no code_dept_pay
from gh_deposit_c a
left join zd_cheque_type b on a.cheque_type = b.code
left join a_employee_mi psn on psn.code = a.price_opera
--WHERE price_date between ${BEGIN_DATE} and ${END_DATE}
where EXISTS
(
select patient_id,times
from uh_dc_pi_temp t
where t.patient_id=a.patient_id
)
之前我使用的是convert,会出现‘从数据类型 varchar 转换为 numeric 时出错。错误。改成cast后也是这样。
附:patient_id---char(12),.item_no--smallint,ledger_sn--smallint.

  • 写回答

1条回答

  • sliang733 2016-03-04 07:03
    关注

    这个就是因为字符串字段中的值有不是数字的记录

    要么将存在的记录修改好,要么自己写一个转换数字的函数,把非数字的字符串转成null或者0这样

    评论

报告相同问题?

悬赏问题

  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果