我遇到了问题。我使用存储过程来检索一些数据集。所有DB期望和检索结果在0秒内优化此过程。但是过了几天它需要花费太多时间,我必须在3,4天后使用autojob重新编译它。重新编译后再次在0秒内检索结果。 任何人都可以帮助我解决这个问题吗?
代码:
DECLARE @account BIGINT = 2210124537100405
WITH RECOMPILE
BEGIN
-- declare @account bigint =101125953510789
SELECT CONVERT(VARCHAR, table2.number) AS Claim_No,
Table2.account,
CONVERT(VARCHAR(10), B_DATE, 101) AS BILLDATE,
table2.Location_Code,
DOS,
CONVERT(VARCHAR, DOS, 101) AS DOS_SERVICE,
(
SELECT ISNULL(p_name, '') + ' ' + ISNULL(p_2name, '') + '. ' +
ISNULL(p_3name, '')
FROM table3 p
WHERE p.p_code = a_p
) AS A_Pn,
B_Phn,
S_Phn,
ISNULL(C_Total, 0.00) C_Total,
ISNULL(Amt_P, 0.00) Amt_P,
PA_NUMBER,
Re_Number,
Facility_Code,
ho_to = CASE ISNULL(Ho_To, '')
WHEN '' THEN dot
ELSE Hos_To
END,
Hos_Fr = CASE ISNULL(Hos_From, '')
WHEN '' THEN dost
ELSE Hos_From
END,
PRI_STATUS,
SEC_STATUS,
OTH_STATUS,
PAT_STATUS,
Employment,
Claim_Status,
Claim_Status_Date,
Accident_State,
Phy_Exam_Code,
Phy_Exam_Desc,
Ordering_Physician,
ICN_Number,
Block1213,
ISNULL(Pri_Ins_Payment, 0.00) AS Pri_Ins_Payment,
ISNULL(Sec_Ins_Payment, 0.00) AS Sec_Ins_Payment,
ISNULL(Oth_Ins_Payment, 0.00) AS Oth_Ins_Payment,
ISNULL(Patient_Payment, 0.00) AS Patient_Payment,
ISNULL(Adjustment, 0.00) AS Adjustment,
ISNULL(Amt_Due, 0.00) AS Amt_Due,
DX_Code1,
DX_Code2,
DX_Code3,
DX_Code4,
DX_Code5,
DX_Code6,
DX_Code7,
DX_Code8,
POS,
table2.PTL_Status,
ISNULL(table2.resolve, 0) resolve,
table2.Patient_Payment_Plan,
Is_Self_Pay,
table2.Deleted,
UPPER(table2.Created_By) AS Created_By,
CONVERT(DATETIME, CONVERT(VARCHAR, table2.Created_Date, 101)) AS
Created_Date,
table2.Modified_By,
table2.Modified_Date,
IS_DRAFT AS Is_draft,
ISNULL(ClaimTemp_Category.Temp_Name, '') AS Temp_Name,
(
SELECT COUNT(claim_no) AS table2_Submitted
FROM table2_Submitted
WHERE Claim_No = table2.Claim_No
AND DELETED = 0
) AS table2_Submitted,
(
SELECT COUNT(claim_payments_id) AS CLAIMS_PAYMENT FROMtable4
WHERE Claim_No = table2.Claim_No
AND DELETED = 0
) AS CLAIMS_PAYMENT
FROM table2
JOIN table3
ON table2.attending_physician = table3.provider_code
LEFT OUTER JOIN ClaimTemp_Category
ON table2.no = ClaimTemp_Category.Claim_No
WHERE (
table2.account = @account
OR table2.DRAFT_account = @account
)
AND ISNULL(table2.DELETED, 0) = 0
ORDER BY
DOS DESC
END