a quick and easy solution that would get you close to where you want to be would be to do a union similar to
select 'type1objects' as objecttype
datepart(dw, currentdatetime) as dayofweek,
number_type_1_objects as numberofobjects,
count(number_type_1_objects) as rows
from yourtable
group by convert(varchar(10), currentdatetime,101), datepart(dw, currentdatetime), number_type_1_objects
union
select 'type2objects' as objecttype
datepart('d',currentdatetime) as dayofweek,
number_type_2_objects as numberofobjects,
count(*) as rows
from yourtable
group by convert(varchar(10),currentdatetime,101), datepart(dw,currentdatetime), number_type_2_objects
and so on for each object column. that should get you an approximation of the data you are getting now without the use of those crazy variables and cursors, buildings not withstanding. you could probably join the buildings table in though, just adding it to the group by and be done with that as well. not sure though as i have no idea what the relationship would be drawn on...
nathan gonzalez
2010-06-01 19:54:46