Query is taking very long to execute

  • I would initially change this:

    FROM Dbo.[VDSMeetingInformation] VMI

    INNER JOIN dbo.[DelimitedSplit8K](@fund_id,',') fnsplt ON VMI.FundID =(CASE WHEN fnsplt.item IS NULL THEN VMI.FundID ELSE fnsplt.item END)

    WHERE VMI.customerID = @customer_id

    AND VMI.MeetingDate BETWEEN @Start_date AND @End_date

    AND VMI.MeetingID > 0

    AND VMI.Country IS NOT NULL

    AND (

    VMI.CompanyName LIKE COALESCE(@Value1,VMI.CompanyName ) +'%'

    OR

    VMI.ticker LIKE COALESCE(@Value1,VMI.Ticker)+'%'

    OR

    VMI.SecurityID LIKE COALESCE(@value1,VMI.SecurityID) +'%'

    )

    To this:

    FROM Dbo.[VDSMeetingInformation] VMI

    WHERE VMI.customerID = @customer_id

    AND VMI.MeetingDate BETWEEN @Start_date AND @End_date

    AND VMI.MeetingID > 0

    AND VMI.Country IS NOT NULL

    AND (

    VMI.CompanyName LIKE @Value1 + '%'

    OR

    VMI.ticker LIKE @Value1 + '%'

    OR

    VMI.SecurityID LIKE @value1 + '%'

    OR

    @value1 IS NULL

    )

    AND(

    EXISTS ( SELECT 1 FROM dbo.[DelimitedSplit8K](@fund_id,',') fnsplt WHERE VMI.FundID = fnsplt.item)

    OR

    @fund_id IS NULL

    )

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing post 16 (of 15 total)

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