I am new to this. I have the following code which inside and SSID package takes too long to excecute.
This statement is meant to find the best lawyer (taking under consideration some productivity and capacity factors) and write its ID to a temporary table ...BUT IT TAKES TOO LONG.
Any Suggestions??? I even tried... disabling the trigers
ALTER TABLE TB_TEMPLawyer DISABLE TRIGGER ALL
ALTER TABLE TB_LAWYERS DISABLE TRIGGER ALL
ALTER TABLE TB_PCRelation DISABLE TRIGGER ALL
ALTER TABLE TB_CASES DISABLE TRIGGER ALL
ALTER TABLE TB_TEMPaccount DISABLE TRIGGER ALL
INSERT INTO TB_TEMPLawyer
(LawyerAutoIDTEMP)
SELECT TOP (1) TB_LAWYERS.LawyerAutoID
FROM TB_PCRelation INNER JOIN
TB_CASES ON TB_PCRelation.PostalCode = TB_CASES.CustomerPostalCode INNER JOIN
TB_LAWYERS ON TB_PCRelation.PCLawyerID = TB_LAWYERS.LawyerID INNER JOIN
TB_TEMPaccount ON TB_CASES.Account = TB_TEMPaccount.TempAccount
WHERE (TB_CASES.LASYstatus = '2') AND (TB_CASES.LawyerID = 'NONE') AND (TB_LAWYERS.Activity = 'ACTIVE') AND
(TB_LAWYERS.Relation_Type = 'EXTERNAL') AND (TB_CASES.TotalMLUSBBexposure BETWEEN TB_LAWYERS.MINAmount AND
TB_LAWYERS.MAXamount) AND (TB_LAWYERS.CaseLimitMONTHLY >= TB_LAWYERS.CaseLimitMONTHLYactual) AND
(TB_LAWYERS.CaseLimitDAILY >= TB_LAWYERS.CaseLimitDAILYactual) AND (TB_LAWYERS.Productivity <> '0')
ORDER BY TB_LAWYERS.Productivity DESC
ALTER TABLE TB_TEMPLawyer ENABLE TRIGGER ALL
ALTER TABLE TB_LAWYERS ENABLE TRIGGER ALL
ALTER TABLE TB_PCRelation ENABLE TRIGGER ALL
ALTER TABLE TB_CASES ENABLE TRIGGER ALL
ALTER TABLE TB_TEMPaccount ENABLE TRIGGER ALL
First, triggers would have nothing to do with the performance. You are only inserting one row.
There are two problems you could face in an insert of this sort:
Run the query in SSMS.
Judging from the naming conventions, I would be suspicious of this join:
FROM TB_PCRelation INNER JOIN
TB_CASES
ON TB_PCRelation.PostalCode = TB_CASES.CustomerPostalCode
There is not an obvious restriction on the cases. You very well might have a lot of lawyers and a lot of cases in a single postal code.
However, this is just speculation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.