• ChrisM@Work (3/6/2013)


    There's no data in the table for February 😛

    -- last month:

    SELECT

    MonthStart = DATEADD(month,DATEDIFF(month,0,getdate())-1,0), -- 1st Feb

    MonthEnd = DATEADD(month,DATEDIFF(month,0,getdate()),0) -- 1st Mar

    -- month before last:

    SELECT

    MonthStart = DATEADD(month,DATEDIFF(month,0,getdate())-2,0), -- 1st Jan

    MonthEnd = DATEADD(month,DATEDIFF(month,0,getdate())-1,0) -- 1st Feb

    -- Usage:

    SELECT *

    FROM Tussen_Tickets

    WHERE Ticket_Closed_DateTime >= DATEADD(month,DATEDIFF(month,0,getdate())-1,0) -- greater than or equal to

    AND Ticket_Closed_DateTime < DATEADD(month,DATEDIFF(month,0,getdate()),0) -- LESS THAN

    I do get 160 rows for february from the Tusen_Tickets table. But this is the Original not aggregated table Tussen_Tickets.

    I'm getting desperate now, because I dont get any result from the last query with the 2 temp tables.