来自 新葡亰数据库 2019-11-27 16:48 的文章
当前位置: 澳门新葡亰app > 新葡亰数据库 > 正文

SQL server 和 Oracle 中列转行的小操作

Oracle:

SQL数据收取,现身数据类型调换错误,求大神帮衬看一下。 1C
select a.patient_id+'_'+cast(a.item_no as varchar+'_'+cast(a.ledger_sn as varchar 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}

create table zjhis.mz_zdxx_zl

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+'_'+cast(a.ledger_sn as varchar 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
澳门新葡亰官网APP,from uh_dc_pi_temp t
where t.patient_id=a.patient_id
)

as

union all

select a.sfsb,

select a.patient_id+'_'+cast(a.item_no as varchar+'_'+cast(a.ledger_sn as varchar pk_pay,null pk_dcpv,null pvcode,'SDDYRMYY_G' code_group,'SDDYRMYY' code_org ,
cheque_type code_pay_mode,b.name name_澳门新葡亰app,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}

wm_concat(a.zdmc) as 诊断 from zjhis.mz_zdxx a

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+'_'+cast(a.ledger_sn as varchar 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,.item_no--smallint,ledger_sn--smallint.

group by a.sfsb

直接能够行使 wm_concat 函数

 

SQl SERVER :

  select t.patient_id,
       t.times,
       [ values ] = stuff((select ',' + icd_name
                             from sx2017.dbo.mz_visit_diagnose
                            where patient_id = t.patient_id
                              and times = t.times
                              for xml path('')), 1, 1, '')
  from sx2017.dbo.mz_visit_diagnose t
 group by patient_id, times
patient_id, times 为关连字段

 

   

 

本文由澳门新葡亰app发布于新葡亰数据库,转载请注明出处:SQL server 和 Oracle 中列转行的小操作

关键词: