问题描述
- 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
GOALTER 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 DATETIMEIF @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
时间: 2024-08-01 04:26:34