• TheSQLGuru (5/5/2015)


    You can do a simple analysis of how many rows per hour to see if that metric makes sense.

    Here's a query that makes this suggestion pretty simple:

    WITH SampleTimes (t) AS

    (

    SELECT CAST(82860 AS FLOAT)

    UNION ALL SELECT 24480

    )

    SELECT TimeSlot

    ,DistributionByHour=COUNT(

    CASE WHEN t BETWEEN TimeSlotOffsetSeconds AND TimeSlotOffsetSeconds + 3600

    THEN 1

    END)

    FROM SampleTimes a

    CROSS APPLY dbo.CalculateTimeSlots('hour', 1, NULL, NULL) b

    GROUP BY TimeSlot;

    Substitute the SampleData CTE with your table of interest. The CalculateTimeSlots function can be found here: Time Slots - An Essential Extension to Calendar Tables[/url]


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St