I have a friend who is using c# Linq to report on the following table:
varchar(50) name
datetime when
The customer wants to pick what columns to summarize, like Total for this year, Total for Last year, Total for two weeks ago, etc. Each column would have some begin and end time they summarize with a count. I did a quick select statement for him:
select A.name as [Name],
(select count(*) from mytable B where A.name = B.name and
datepart(yy, when) = datepart(yy,getdate())) as [This Year],
(select count(*) from mytable B where A.name = B.name and
datepart(yy, when) = (datepart(yy,getdate()) - 1)) as [Last Year]
from (select distinct name from mytable) A
I also suggested he make each calculation field a delegate so he could contain the calculation mess outside of the query. Assuming each delegate would have a start and end date which calculated how many hits occurs for each distinct Name, anyone want to take a stab at what the Linq c# code would look like?