Terrible code, trying to tweak

  • I know this is terrible, is there anyone who can assist me tweak this thing? I am an operations DBA and this proc causes me heartache in the dB...

    P.S. I have added necessary indexes but the proc is legacy code and poorly written...its certainly not taking advantage of SQL 2008 features...Can someone help me? :w00t:

    USE [databaseName]

    GO

    /****** Object: StoredProcedure [dbo].[sp_rpt_pipedetail_processor_test] Script Date: 07/21/2010 11:44:15 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    ALTER PROCEDURE [dbo].[sp_rpt_pipedetail_processor_test]

    (

    @CategoryId int,

    @TeamId int,

    @EmployeeId int,

    @RequestingEmployeeID int,

    @GetTempLoans bit

    )

    AS

    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

    Declare @init Table (

    loannum varchar(15) primary key,

    submitdate datetime,

    init_RushPurchase smallint,

    init_express_flow bit,

    init_doc_order_dt datetime,

    init_lockreceived datetime,

    init_reviewed_by_funding datetime,

    init_review_date datetime,

    init_file_name varchar(25),

    init_dtp_date datetime,

    init_submit_uw_date datetime,

    init_doc_signdt datetime,

    init_package_sent_date datetime,

    init_package_rcvd_date datetime,

    init_to_rework_date datetime,

    init_from_rework_date datetime,

    init_to_renog_date datetime,

    init_from_renog_date datetime,

    init_to_resell_date datetime,

    init_from_resell_date datetime,

    init_clear_to_fund datetime,

    init_intro_call_date datetime,

    init_to_funding_date datetime,

    init_est_close datetime,

    current_est_COE_dt datetime,

    init_uw_approval_date datetime,

    statuscode smallint,

    init_cema bit,

    appdate datetime,

    uw_received_date datetime

    )

    Insert into @init

    Select init.loannum,

    init.submitdate,

    initext.init_RushPurchase,

    init.init_express_flow,

    init.init_doc_order_dt,

    initext.init_lockreceived,

    init.init_reviewed_by_funding,

    init.init_review_date,

    init.init_file_name,

    init.init_dtp_date,

    init.init_submit_uw_date,

    init.init_doc_signdt,

    init.init_package_sent_date,

    init.init_package_rcvd_date,

    init.init_to_rework_date,

    init.init_from_rework_date ,

    init.init_to_renog_date ,

    init.init_from_renog_date ,

    init.init_to_resell_date ,

    init.init_from_resell_date ,

    init.init_clear_to_fund,

    init.init_intro_call_date,

    init.init_to_funding_date,

    init.init_est_close,

    init.current_est_COE_dt ,

    init.init_uw_approval_date,

    init.statuscode ,

    init.init_cema,

    init.appdate,

    init.uw_received_date

    From tbl_ldf_loaninit init inner join tbl_ldf_loaninit_ext initext on init.loannum = initext.loannum

    Where (init.init_fund_dt IS NULL)

    AND (init.init_dtp_date IS NOT NULL)

    AND (init.init_temp_loan = @GetTempLoans)

    AND (init.init_prov_funded_date IS NULL)

    AND (init.init_cancel_date IS NULL)

    AND (init.init_denied_date IS NULL)

    AND (init.init_submit_to_cancel_dt IS NULL)

    AND (

    ( (init_to_rework_date IS NULL OR init_from_rework_date IS NOT NULL)

    AND (init_to_resell_date IS NULL OR init_from_resell_date IS NOT NULL)

    AND (init_to_renog_date IS NULL OR init_from_renog_date IS NOT NULL)

    ) or

    (

    (init.init_to_rework_date IS NOT NULL AND init.init_from_rework_date IS NULL)

    OR (init_to_resell_date IS NOT NULL AND init_from_resell_date IS NULL)

    OR (init_to_renog_date IS NOT NULL AND init_from_renog_date IS NULL)

    )

    )

    SELECT

    init.loannum as [LoanNum],

    init.init_file_name [File Name],

    mtgtype.mtgtype as [Mortgage Type],

    lpp.Description AS Purpose,

    mtg.programcode [Program],

    mtg.subjectstate [State],

    case when st.EOR_State = 1 then CONVERT(bit, 1) else CONVERT(bit, 0) end AS [Is EOR],

    ---BEGIN STATUS GROUP----

    case when general.scd_Description = 'Prime'

    AND fin.scd_Description LIKE '%CONF%'

    AND mtg.lienposition = 1

    AND fin.scd_Description LIKE '%FXD%'

    AND mtg.purposeofloan <> 1

    AND st.EOR_State is null

    AND mtg.mtg_ispiggy = 0

    AND isnull(mtg.mtg_cc_loan_no,'') = ''

    AND subor.Maxofsub_agree_date is null

    AND mtg.subjectstate not in ('NY','AK','HI')

    AND (

    (uw.uw_score >= 680 and cat.categoryname = 'Prime')

    OR

    (uw.uw_score >= 660 and cat.categoryname = 'Non-Prime')

    )

    AND (

    (calc.LTV <= 0.700 and cat.categoryname = 'Prime')

    OR

    (calc.LTV <= 0.650 and cat.categoryname = 'Non-Prime')

    )

    AND init.init_express_flow = 1

    then

    case --Express Flow

    when init.init_dtp_date is not null and

    loaninit_ext.init_stips_received_date is null and

    init.init_package_sent_date is null

    then '1. Loan Received'

    when loaninit_ext.init_stips_received_date is not null and

    init.init_doc_signdt is null and

    init.init_package_sent_date is null

    then '2. Stips Received'

    when init.init_doc_signdt is not null and

    init.init_package_sent_date is null

    then '3. Doc Signing Scheduled'

    when init.init_package_sent_date is not null and

    init.init_package_rcvd_date is null

    then '4. Docs Out'

    when init.init_package_rcvd_date is not null and

    uw.uw_init_apprvl_date is null and

    vw_appraisal.appraisalReceiveDate is null

    then '5. Docs Back'

    when uw.uw_init_apprvl_date is not null and

    vw_appraisal.appraisalReceiveDate is not null and

    init.init_reviewed_by_funding is null

    then '6. Approved With Conditions'

    when init.init_reviewed_by_funding is not null and

    init.init_clear_to_fund is null

    then '7. Reviewed By Funding'

    when init.init_clear_to_fund is not null

    then '8. Clear To Fund'

    end

    else

    case --Purchase Flow

    when mtg.purposeofloan = 1

    then

    case

    when (init.init_dtp_date is not null) and

    loaninit_ext.init_stips_received_date is null and

    uw.uw_init_apprvl_date is null

    then '1. Loan Received'

    when loaninit_ext.init_stips_received_date is not null and

    uw.uw_init_apprvl_date is null

    then '2. Stips Received'

    when uw.uw_init_apprvl_date is not null and

    fund.ws_assignto_id = 0

    then '3. Approved With Conditions'

    when fund.ws_assignto_id <> 0 and

    init.init_package_sent_date is null

    then '4. Reviewed By Funding'

    when init.init_package_sent_date is not null and

    mtg.subjectstate = 'CA' and

    init.init_package_rcvd_date is null

    then '5. Docs Out'

    when init.init_package_sent_date is not null and

    mtg.subjectstate <> 'CA' and

    init.init_clear_to_fund is null

    then '5. Docs Out'

    when init.init_package_rcvd_date is not null and

    mtg.subjectstate = 'CA' and

    init.init_clear_to_fund is null

    then '6. Docs Back'

    when init.init_clear_to_fund is not null

    then '7. Clear To Fund'

    end

    else

    case --Normal Flow (1st TD Refi and SA 2nd)

    when (init.init_dtp_date is not null) and

    loaninit_ext.init_stips_received_date is null and

    init.init_package_sent_date is null

    then '1. Loan Received'

    when loaninit_ext.init_stips_received_date is not null and

    uw.uw_init_apprvl_date is null and

    init.init_package_sent_date is null

    then '2. Stips Received'

    when uw.uw_init_apprvl_date is not null and

    init.init_doc_signdt is null and

    init.init_package_sent_date is null

    then '3. Approved With Conditions'

    when init.init_doc_signdt is not null and

    init.init_package_sent_date is null

    then '4. Doc Signing Scheduled'

    when init.init_package_sent_date is not null and

    init.init_package_rcvd_date is null

    then '5. Docs Out'

    when init.init_package_rcvd_date is not null and

    init.init_reviewed_by_funding is null

    then '6. Docs Back'

    when init.init_reviewed_by_funding is not null and

    init.init_clear_to_fund is null

    then '7. Reviewed By Funding'

    when init.init_clear_to_fund is not null

    then '8. Clear To Fund'

    end

    end

    end as [Status Group],

    ---END STATUS GROUP----

    lst.Status AS [Workflow Status],

    CONVERT(varchar(7), statm.statlvl) + ' ' + statm.statdetail as [Chloe Status],

    init.init_express_flow AS [Rush],

    init.init_cema as [CEMA],

    Occ.planname as Occupancy,

    pTeam.tsch_name AS [Proc Team],

    --need Processing Manager

    CASE WHEN emp.first_name is null THEN null ELSE ISNULL(emp.first_name, '') + ' ' + ISNULL(emp.last_name, '') END AS [Processor],

    sTeam.tsch_name AS [Sales Team],

    mtg.loname as [Sales Agent],

    --need SMA

    Case When fund.[ws_assignto_id]<>0 then femp.[first_name] + ' ' + femp.[last_name] else null End AS [Funder],

    --need Escrow Officer

    CASE WHEN uwemp.first_name is null THEN null ELSE ISNULL(uwemp.first_name, '') + ' ' + ISNULL(uwemp.last_name, '') END AS [Underwriter],

    CASE WHEN emp_1.first_name is null THEN null ELSE ISNULL(emp_1.first_name, '') + ' ' + ISNULL(emp_1.last_name, '') END AS [Appraisal Coordinator],

    convert(int, mtg.loanamount) AS [Loan Amount],

    CONVERT(VARCHAR(7), Round(calc.LTV * 100,2)) + '%' AS LTV,

    CONVERT(VARCHAR(7), Round(calc.CLTV * 100,2)) + '%' AS CLTV,

    init.appdate AS [App Date],

    init.init_dtp_date AS [DTP],

    init.init_intro_call_date AS [Intro Call],

    Case when ( init.init_est_close is not null and init.current_est_COE_dt is null) then init.init_est_close else init.current_est_COE_dt end AS COE,

    init.init_lockreceived AS [Locked],

    prc.prc_lockexp AS [Lock Expiration],

    case when prc.prc_lockexp is not null then datediff(day,prc.prc_lockexp,getdate())*-1 else 0 end as [Days Until Lock Expiration],

    loaninit_ext.init_stips_received_date AS [Stips Received],

    prov_1.orderdate AS [Title Ordered],

    prov_1.receivedate AS [Title Received],

    vw_appraisal.appraisalOrderDate AS [Appraisal Ordered],

    vw_appraisal.appraisalApptDate AS [Appraisal Appt],

    vw_appraisal.appraisalReceiveDate AS [Appraisal Received],

    init.init_submit_uw_date AS [Submitted to UW],

    init.uw_received_date AS [UW Received],

    uw.uw_init_apprvl_date AS [Approved On],

    --Need Submit for SIgn Off

    init.init_doc_signdt AS [Doc Signing],

    loaninit_ext.EarliestSigningDt AS [Earliest Signing],

    init.init_package_sent_date AS [Docs Out],

    init.init_package_rcvd_date AS [Docs Back],

    init.init_review_date AS [Review],

    init.init_to_funding_date AS [To Funding],

    init.init_clear_to_fund AS [Clear To Fund],

    escr.escrow_ready_dt AS [Escrow Ready],

    conlog.last_con_log_date AS [Last Con Log],

    disclosure.last_disclosure_date AS [Last Disclosed],

    case when expectations.ExpectationDate is not null then expectations.ExpectationDate else NULL end as [Next Expectation],

    case when pr.loannum is null then Convert(bit, 0) else Convert(bit, 1) end as [Has Paperless],

    case when il.loannum is null then Convert(bit, 0) else Convert(bit, 1) end as Important,

    case when il.loannum is null then CONVERT(int, 0) else il.ImportantLoanTypeId end as ImportantType,

    lc.Comment as Comments,

    --Need Low Appraisal Value

    --Need Has Econsent

    init.init_to_rework_date AS [To Rework],

    init.init_from_rework_date AS [From Rework],

    init.init_to_renog_date AS [To Reneg],

    init.init_from_renog_date AS [From Reneg],

    init.init_to_resell_date AS [To Resell],

    init.init_from_resell_date AS [From Resell],

    case when ((init.init_to_rework_date IS NOT NULL AND init.init_from_rework_date IS NULL)

    OR (init_to_resell_date IS NOT NULL AND init_from_resell_date IS NULL)

    OR (init_to_renog_date IS NOT NULL AND init_from_renog_date IS NULL))

    then CONVERT(bit, 1)

    else CONVERT(bit, 0) end as [Is Code Red]

    FROM @init init

    JOIN tbl_ldf_mtgtype mtg ON init.loannum=mtg.loannum

    JOIN tbl_co_employees emp ON mtg.processor_id= emp.id AND (ISNULL(@EmployeeId,-1) = -1 OR emp.id = @EmployeeId)

    JOIN tbl_co_team_sch_proc pTeam ON pTeam.tsch_id = emp.procteamid

    JOIN tbl_co_team_grouping grp ON pTeam.tsch_id=grp.teamid AND (ISNULL(@TeamId,-1)=-1 OR pTeam.tsch_id=@TeamId)

    JOIN tbl_co_team_category cat ON grp.categoryid=cat.categoryid AND cat.categorytype = 'Processing' AND (ISNULL(@CategoryId,-1) = -1 OR cat.categoryid = @CategoryId)

    JOIN tbl_co_employees sales ON sales.id = mtg.mtg_lo_id

    JOIN tbl_co_team_sch sTeam ON sTeam.tsch_id = sales.teamid

    LEFT OUTER JOIN tbl_ldf_wrksch uwsch ON uwsch.loannum = mtg.loannum AND uwsch.flowid = 4

    LEFT OUTER JOIN tbl_co_employees uwemp ON uwemp.id = uwsch.ws_assignto_id

    LEFT OUTER JOIN tbl_prc_lock prc ON mtg.loannum = prc.loannum

    LEFT OUTER JOIN tbl_su_loanpurpose lpp ON mtg.purposeofloan = lpp.PurpId

    LEFT OUTER JOIN tbl_ldf_escrow escr ON init.loannum = escr.loannum

    LEFT OUTER JOIN tbl_su_statusmaster statm ON init.statuscode = statm.statdetailid

    LEFT OUTER JOIN tbl_ldf_uw uw ON mtg.loannum = uw.loannum

    LEFT OUTER JOIN tbl_ldf_calcs calc ON mtg.loannum = calc.loannum

    LEFT OUTER JOIN

    (SELECT LoanNumber, min(ExpectationDate) as ExpectationDate

    FROM LoanExpectations where ExpectationDate > GETDATE() - 1

    group by LoanNumber) expectations ON mtg.loannum = expectations.LoanNumber

    LEFT OUTER JOIN tbl_su_states st ON mtg.subjectstate = st.abreviation

    LEFT OUTER JOIN

    (SELECT loannum, MAX(sub_agree_date) AS MaxOfsub_agree_date

    FROM tbl_ldf_subordinations

    GROUP BY loannum) subor ON mtg.loannum = subor.loannum

    LEFT OUTER JOIN

    (SELECT tbl_ldf_appraisals.loannum,

    tbl_ldf_appraisals.orderdate AS appraisalOrderDate,

    tbl_co_providerdatabase.providername AS appraisalCompany,

    tbl_ldf_appraisals.prov_require_date AS appraisalApptDate,

    tbl_ldf_appraisals.receivedate AS appraisalReceiveDate,

    tbl_su_apraisaltypes.apprtype AS appraisalOrderType,

    tbl_ldf_appraisals.prov_require_date

    FROM

    (SELECT loannum, MIN(apprid) AS myMin

    FROM tbl_ldf_appraisals

    WHERE (uwexclude = 0)

    AND (inactive = 0)

    AND (orderdate IS NOT NULL)

    AND (appr_canceldate IS NULL)

    OR

    (uwexclude = 1)

    AND (inactive = 0)

    AND (orderdate IS NOT NULL)

    AND (appr_canceldate IS NULL)

    AND (apprvalue IS NULL OR apprvalue = 0)

    OR

    (appraiserID = 13534) --Recycled Internally

    GROUP BY loannum) apprMin

    JOIN tbl_ldf_appraisals ON apprMin.loannum = tbl_ldf_appraisals.loannum AND apprMin.myMin = tbl_ldf_appraisals.apprid

    LEFT OUTER JOIN tbl_su_apraisaltypes ON tbl_ldf_appraisals.apprtypeid = tbl_su_apraisaltypes.apprtypeid

    LEFT OUTER JOIN tbl_co_providerdatabase ON tbl_ldf_appraisals.appraiserId = tbl_co_providerdatabase.id) vw_appraisal ON mtg.loannum = vw_appraisal.loannum

    LEFT OUTER JOIN tbl_ldf_providers prov ON mtg.loannum = prov.loannum AND prov.providertype = 37

    LEFT OUTER JOIN tbl_ldf_providers prov_1 ON init.loannum = prov_1.loannum AND prov_1.providertype = 39

    LEFT OUTER JOIN tbl_myprograms myp ON mtg.programcode = myp.myprogram

    LEFT OUTER JOIN tbl_su_CommonData AS general ON myp.general_descID = general.scd_KeyValue

    LEFT OUTER JOIN tbl_su_CommonData AS fin ON myp.Finance_Desc_Id = fin.scd_Recid

    LEFT OUTER JOIN tbl_co_employees emp_1 ON mtg.coordinator_id = emp_1.id

    LEFT OUTER JOIN

    (SELECT loannum, MAX(event_date) AS last_con_log_date

    FROM tbl_ldf_events

    WHERE tbl_ldf_events.event_type_id = 1 AND tbl_ldf_events.subject LIKE 'Borrower Contact-%'

    GROUP BY loannum) conlog ON init.loannum = conlog.loannum

    LEFT OUTER JOIN tbl_ldf_loaninit_ext loaninit_ext ON init.loannum = loaninit_ext.LoanNum

    LEFT OUTER JOIN tbl_myprograms MP on mtg.programcode = MP.myprogram

    LEFT OUTER JOIN tbl_setupoccupancy Occ on Occ.id = mtg.propertywillbe

    LEFT OUTER JOIN tbl_ldf_wrksch fund ON init.loannum = fund.loannum AND fund.flowid=11

    LEFT OUTER JOIN tbl_co_employees femp ON fund.ws_assignto_id = femp.id

    LEFT OUTER JOIN PaperlessRepository pr on pr.LoanNum = init.loannum

    LEFT OUTER JOIN ImportantLoan il on il.LoanNum = init.loannum and il.EmployeeId = @RequestingEmployeeID

    LEFT OUTER JOIN LoanComment lc on lc.LoanNum = init.loannum and lc.EmployeeId = @RequestingEmployeeID

    LEFT OUTER JOIN tbl_su_mtgtype mtgtype on mtgtype.mtgcode = mtg.mortgageappliedfor

    LEFT OUTER JOIN

    (SELECT loannum, MAX(disclosure.process_dt) AS last_disclosure_date

    FROM tbl_ldf_batch_detail disclosure

    WHERE disclosure.process_id IN (71,72,73) AND disclosure.process_dt is not null

    GROUP BY loannum) disclosure ON disclosure.loannum = mtg.loannum

    LEFT OUTER JOIN CurrentLoanStatus cls ON cls.LoanNumber = init.loannum

    LEFT OUTER JOIN LoanStatusType lst ON lst.LoanStatusTypeID = cls.LoanStatusID

    SET TRANSACTION ISOLATION LEVEL READ COMMITTED

    GO


    Aurora

  • You're right about it being terrible. I really think it would take being on the system to fix it.

    └> bt



    Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • rule of thumb for me is if the @TableVariable has anywhere near 1000 rows or more, it should be changed to a #temp table instead...

    after that, it would take some decent analysis to see what can be improved or fixed.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Uhh... words fail me, but I'd be willing to discuss an hourly rate to untangle the mess.

    I agree, based on what you're doing here, I would suggest switching the table variable to a temp table.

    Also, I didn't get through all the second SELECT query, but in the first you have a bunch of OR clauses. Those are going to hurt performance quite a bit. You might be better off making those into a UNION ALL so that you don't have to do OR. Just a thought.

    Other than that... woof. What's the actual execution plan look like? Can you post it?

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thanks everyone, I know it stinks, believe me I am all over the dev regarding it, but I'm not to hard on him because its a legacy piece of code that he wants to improve (if possible)... and I definitely want to improve because of the performance hit we take when its called.

    I will work on getting the sample data...

    Thanks again for all your help!


    Aurora

  • Grant Fritchey (7/22/2010)


    Uhh... words fail me, but I'd be willing to discuss an hourly rate to untangle the mess.

    Agreed. That looks like a good couple days of work to rewrite. Advice is one thing, doing free consulting is quite another...

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Your company needs to hire good software engineer(s) who understand not only software but relational database architecture to design a good solution to this.

    It would save them some time if they had a specification or requirements document to work from. You can not design a solution to a problem unless you understand what the problem is... and I've seen this all too often in my career.

    The probability of survival is inversely proportional to the angle of arrival.

  • I agree a temp table will server better here because the optimizer does not maintain statistics on table variables, so the optimizer is going to assume 1 row in the table.

    Other than this you need to eliminate some of the mess. You should look at cleaning up the code and I would even consider an indexed view to speed up performance (the tradeoff here is storage and extra maintenance)

  • Not asking for you to rewrite and I am sure i did not pose my question that way...

    To those of you who have been most understanding and helpful, thank you. As I have mentioned it is legacy code, we inherited the code and want to fix it or rewrite it. I am not asking for anyone to rewrite it for me...I was asking for overall best practices advice since I am an ops DBA not the developer.

    Joe thank you, I will pass on the best practice advice...I try very hard to stay on these devs, and when we crack open the hood and see something like this it makes us all cringe...

    To those who were critical, unhelpful and frankly just rude...I have been on this forum and visiting this web site for over 8 years, I have never encountered such rudeness...This is a help forum not career builder..If you are looking for work hit up DICE. If you don't want to help, then do what your mother should have told while growing up:

    If you don't have anything nice to say don't say anything at all.


    Aurora

  • Wow guys you were super critical here...We bought a company, and yes they had legacy code and ill if any at all standards...That being said, we are trying to fix it.

    Thanks again, if you made any attempt to advise...


    Aurora

  • Things certainly got a little harsher than they should have and I guess I started it with my comment. Apologies. I meant it as a joke.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thanks Grant, and I did take your comment with humor, I mean believe me, I know that code is a mess, lol

    I think what Joe points out is just what I have been screaming about...I have also called for a rewrite but as you know sometimes in an Enterprise environment, that is 24/7 we are forced to live w/ the legacy code until we can get to "that project".

    Thanks again...


    Aurora

  • MegaDBA (7/22/2010)


    Thanks Grant, and I did take your comment with humor, I mean believe me, I know that code is a mess, lol

    I think what Joe points out is just what I have been screaming about...I have also called for a rewrite but as you know sometimes in an Enterprise environment, that is 24/7 we are forced to live w/ the legacy code until we can get to "that project".

    Thanks again...

    Oh yeah, I know where you're coming from. We've got an app that's about 7 years old. For the majority of that 7 years, this app has suffered from deadlocks, 3-5 a week. We've known how to fix it for about 6 years, 364 days. But, putting in the fix would require a round of testing that the business doesn't want to support. Instead we just go through a quarterly "rediscovery" of the problem, the solution, and the fact that no one will authorize the fix. It's a joy!

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Any luck on converting table variable to temp table?

    Here are the other action you can try.

    * Recompile procedure (Oh yeah, sometimes this works magic.)

    * Gather statistics on the tables included in the SP.

    * tbl_ldf_events : Index will never be used, since there is a LIKE clause on subject. See if there will be difference in performance by commenting this line temporarily.

    * Inline view "apprMin", does it have all the paranethesis Separating OR clauses?

    * "STATUS GROUP" consider having a computed column in the table by updating thru trigger or have this maintained thru application. See difference in trigger being called depending on the database. Also avoid unnecessary triggering.

  • Hey thanks,

    I did change the variable to a temp table...and I recompiled, this gave us immediate gratification and then it started hanging again...

    i will implement the other hints...remove that "like" (good grief are they really doing this) and see how that does...

    @Grant, I can soooo relate to that.


    Aurora

Viewing 15 posts - 1 through 15 (of 27 total)

You must be logged in to reply to this topic. Login to reply