Hi
Before I start, this is the structure of my table, tblStatsSessions.
SessionID (primary key, auto number)
CreationDate (DateTime)
DevelopmentID (Number)
The purpose of the function below(a stored procedure in Access) is to return a Count of SessionID's for the past 7 days and group them by day of the week for a specific DevelopmentID.
For example:
I feed it a DevelopmentID of 1. It then displays the number of sessions for that DevelopmentID for each day within the last 7 days. I use DatePart to display the number of the day of the week rather than the date.
Here is the SQL block:
SELECT DevelopmentID, Count(SessionID) AS Sessions, DatePart ( 'w', CreationDate) as StrDay
FROM tblStatsSessions
WHERE DevelopmentID = @DevelopmentID AND DateDiff('d',CreationDate, Now())<7
GROUP BY DatePart ( 'w', CreationDate), DevelopmentID
ORDER BY CreationDate DESC;
The SQL above works fine until I want to Order By the field 'CreationDate'. To do that I believe I must include CreationDate into the SELECT statement and also include it in the Group By line. However, when I do this, rather than displaying a Count of Session ID's for each day of the week, I get a record for every SessionID (so I presume, every CreationDate).
How do I ensure that I can Order By CreationDate, but not include it in the Select/Group By lines?
Thanks in advance for any help on this.
Shaun
Before I start, this is the structure of my table, tblStatsSessions.
SessionID (primary key, auto number)
CreationDate (DateTime)
DevelopmentID (Number)
The purpose of the function below(a stored procedure in Access) is to return a Count of SessionID's for the past 7 days and group them by day of the week for a specific DevelopmentID.
For example:
I feed it a DevelopmentID of 1. It then displays the number of sessions for that DevelopmentID for each day within the last 7 days. I use DatePart to display the number of the day of the week rather than the date.
Here is the SQL block:
SELECT DevelopmentID, Count(SessionID) AS Sessions, DatePart ( 'w', CreationDate) as StrDay
FROM tblStatsSessions
WHERE DevelopmentID = @DevelopmentID AND DateDiff('d',CreationDate, Now())<7
GROUP BY DatePart ( 'w', CreationDate), DevelopmentID
ORDER BY CreationDate DESC;
The SQL above works fine until I want to Order By the field 'CreationDate'. To do that I believe I must include CreationDate into the SELECT statement and also include it in the Group By line. However, when I do this, rather than displaying a Count of Session ID's for each day of the week, I get a record for every SessionID (so I presume, every CreationDate).
How do I ensure that I can Order By CreationDate, but not include it in the Select/Group By lines?
Thanks in advance for any help on this.
Shaun