SQL 2008 Stored Procedure - multiple counts
Posted on 2011-02-15
Appreciate some help;
Sql 2008 stored procedure or Select statement preferred.
Say I have a 2 column table. Field 1 = Office and Field 2 = DateDue
I wish to count all those records which are earlier than a date (for example lets say GetDate())
I need to group the counts on the Office field.
I need to have 3 separate counts for each office. Less then now, less then now +1 month, and less than now +2 months.
So the result would be a mini recordset
Office Count1 Count2 Count3
1 24 20 0
2 12 23 2
3 0 10 34
4 34 8 0
Can this be done in a single select statement? Perhaps temp table SP perhaps?