22,210
社区成员
发帖
与我相关
我的任务
分享
DECLARE @ST_DATE AS varchar(10)
DECLARE @ED_DATE AS varchar(10)
DECLARE @TEMP_DATE varchar(10)
set @ED_DATE=convert(varchar(10),getdate(),120)
SET @ST_DATE=CONVERT(VARCHAR(10),dateadd(day,-1,@ED_DATE),120)
begin tran
delete hisdb2.dbo.his_charge_acc_i where charge_date>=@ST_DATE and charge_date<@ED_DATE
insert into hisdb2.dbo.his_charge_acc_i
(charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag)
select charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag
from openquery(HIS,'select charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag from data_hrp.HIS_CHARGE_ACC_I')
where charge_date>=@ST_DATE and charge_date<@ED_DATE
commit tran
begin tran
delete hisdb2.dbo.his_charge_acc_mz where charge_date>=@ST_DATE and charge_date<@ED_DATE
insert into hisdb2.dbo.his_charge_acc_mz
(charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag, invoice_type)
select charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag, invoice_type
from openquery(HIS,'select charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag, invoice_type from data_hrp.HIS_CHARGE_ACC_MZ')
where charge_date>=@ST_DATE and charge_date<@ED_DATE
commit tran
begin tran
delete hisdb2.dbo.his_charge_acc_tj where charge_date>=@ST_DATE and charge_date<@ED_DATE
insert into hisdb2.dbo.his_charge_acc_tj
(charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag, invoice_type)
select charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag, invoice_type
from openquery(HIS,'select charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag, invoice_type from data_hrp.HIS_CHARGE_ACC_TJ')
where charge_date>=@ST_DATE and charge_date<@ED_DATE
commit tran
begin tran
delete hisdb2.dbo.his_charge_acc_zy where charge_date>=@ST_DATE and charge_date<@ED_DATE
insert into hisdb2.dbo.his_charge_acc_zy
(charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag)
select charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag
from openquery(HIS,'select charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag from data_hrp.HIS_CHARGE_ACC_ZY')
where charge_date>=@ST_DATE and charge_date<@ED_DATE
commit tran
begin tran
delete hisdb2.dbo.his_charge_pre_i where charge_date>=@ST_DATE and charge_date<@ED_DATE
insert into hisdb2.dbo.his_charge_pre_i
(charge_date, pre_record, oper_code, oper_name, deposit_pre, pay_type_code, patient_type_code, patient_area, patient_code, charge_money, charge_status, old_recipeno)
select charge_date, pre_record, oper_code, oper_name, deposit_pre, pay_type_code, patient_type_code, patient_area, patient_code, charge_money, charge_status, old_recipeno
from openquery(HIS,'select charge_date, pre_record, oper_code, oper_name, deposit_pre, pay_type_code, patient_type_code, patient_area, patient_code, charge_money, charge_status, old_recipeno from data_hrp.HIS_CHARGE_PRE_I')
where charge_date>=@ST_DATE and charge_date<@ED_DATE
commit tran
begin tran
delete hisdb2.dbo.his_charge_pre_o where charge_date>=@ST_DATE and charge_date<@ED_DATE
insert into hisdb2.dbo.his_charge_pre_o
(charge_date, pre_record, oper_code, oper_name, deposit_pre, pay_type_code, patient_type_code, patient_area, patient_code, charge_money, charge_status)
select charge_date, pre_record, oper_code, oper_name, deposit_pre, pay_type_code, patient_type_code, patient_area, patient_code, charge_money, charge_status
from openquery(HIS,'select charge_date, pre_record, oper_code, oper_name, deposit_pre, pay_type_code, patient_type_code, patient_area, patient_code, charge_money, charge_status from data_hrp.HIS_CHARGE_PRE_O')
where charge_date>=@ST_DATE and charge_date<@ED_DATE
commit tran
begin tran
delete hisdb2.dbo.his_outp_clinic where charge_date>=@ST_DATE and charge_date<@ED_DATE
insert into hisdb2.dbo.his_outp_clinic
(charge_date, dept_code, patient_type_code, outp_num)
select charge_date, dept_code, patient_type_code, outp_num
from openquery(HIS,'select charge_date, dept_code, patient_type_code, outp_num from data_hrp.HIS_OUTP_CLINIC')
where charge_date>=@ST_DATE and charge_date<@ED_DATE
commit tran
BEGIN TRAN
delete hisdb2.dbo.his_charge_acc_o where charge_date>=@ST_DATE and charge_date<@ED_DATE
insert into hisdb2.dbo.his_charge_acc_o
(charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag, invoice_type)
select charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag, invoice_type
from openquery(HIS,'select charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag, invoice_type from data_hrp.HIS_CHARGE_ACC_O')
where charge_date>=@ST_DATE and charge_date<@ED_DATE
COMMIT TRAN
begin tran
delete hisdb2.dbo.his_charge_acc_i where charge_date>=@ST_DATE and charge_date<@ED_DATE
if @@ERROR<>0
begin
rollback tran
return 0
end
else
begin
commit tran
end
insert into hisdb2.dbo.his_charge_acc_i
(charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag)
select charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag
from openquery(HIS,'select charge_date, deposit_pre, pay_type_code, patient_type_code, his_irecord, charge_money, patient_code, invoice_no, operator, acc_flag, balance_flag from data_hrp.HIS_CHARGE_ACC_I')
where charge_date>=@ST_DATE and charge_date<@ED_DATE