2 hm1989wz hm1989wz 于 2013.12.03 09:02 提问

SQL存储过程比SQL语句慢,甚至卡死

因公司业务需要,需要每天凌晨从别的系统(Oracle数据库)取前一天的数据,建了存储过程后,发现执行存储过程经常卡死,单独执行却挺快,不知道是哪里出了问题,求大神帮忙分析下,万分感谢!以下为存储过程代码:

USE [HERP_BHYY]
GO
/****** 对象: StoredProcedure [dbo].[sp_GetHISChargeOReceiptDataInHISDBbyDay] 脚本日期: 12/03/2013 08:36:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[sp_GetHISChargeOReceiptDataInHISDBbyDay] @ImpDate as DATETIME
AS
BEGIN
--SET NOCOUNT ON;
DECLARE @ST_DATE AS DATETIME
DECLARE @ED_DATE AS DATETIME
DECLARE @TEMP_DATE DATETIME

IF @ImpDate is not null
begin
    SET @ST_DATE=LEFT(@ImpDate,10)
    SET @ED_DATE=dateadd(day,1,@ST_DATE)
end

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

end

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!