From: Jonathan on
Hi using sql2005, I would like to return summary statistics that are grouped
by weekending date (Friday) between date range start and end parameters.

Any ideas or suggestions appreciated :-)

Many thanks,
Jonathan
From: Plamen Ratchev on
You can use a formula based on well know Friday date (here Jan 5, 1900). Replace the WHERE clause predicate literals
with your parameters for start/end period.

SELECT DATEADD(DAY, (DATEDIFF(DAY, '19000105', date_column) / 7) * 7, '19000112') AS friday_date,
COUNT(*) AS cnt
FROM Foo
WHERE date_column >= '20100101'
AND date_column < '20100401'
GROUP BY DATEADD(DAY, (DATEDIFF(DAY, '19000105', date_column) / 7) * 7, '19000112');

--
Plamen Ratchev
http://www.SQLStudio.com
From: Jonathan on
Awesome, many thanks
Jonathan

"Plamen Ratchev" wrote:

> You can use a formula based on well know Friday date (here Jan 5, 1900). Replace the WHERE clause predicate literals
> with your parameters for start/end period.
>
> SELECT DATEADD(DAY, (DATEDIFF(DAY, '19000105', date_column) / 7) * 7, '19000112') AS friday_date,
> COUNT(*) AS cnt
> FROM Foo
> WHERE date_column >= '20100101'
> AND date_column < '20100401'
> GROUP BY DATEADD(DAY, (DATEDIFF(DAY, '19000105', date_column) / 7) * 7, '19000112');
>
> --
> Plamen Ratchev
> http://www.SQLStudio.com
> .
>