• geert.de.vylder (3/4/2013)


    Hi ChrisM@Work,

    Thank you for your reply. In attachment you will find the executionplan. The Tussen_Tickets table has at this moment 31779 records.

    The query is almost correct. I only had to change Talk = SUM(tt.OnHold) to Talk = SUM(tt.Talk) in the OUTER APPLY.

    I also saw that the Event_Channel is not always filled (NULL) and not always correctly sorted.

    Is that maybe your remark that you saw that my previous post puts column event_channel into the left-hand side along with date, from the Tussen_Ticket table?

    Greetz,

    Geert

    Does event_channel have to be populated, even if there isn't a match in the Tussen_Ticket table?

    Meantime, try this index:

    CREATE NONCLUSTERED INDEX ix_Ticket_Closed_DateTime

    ON [dbo].[Tussen_Tickets] ([Ticket_Closed_DateTime])

    INCLUDE ([Event_Channel],[Tijdsduur],[WrapUp],[OnHold],[DVBIntern],[DVBExtern],[Talk])

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden