Hi
I have the following sql where I am trying to get the number of records created on each day regardless of the time it was created:
this works fine but gives multiple records for the same date as the time is actually different in the underlying data, see below:
If I try to group by the alias I get the following error:
Can anyone tell me how I can group by the alias so that I get a sum of all records on each date regardless of the time portion of the field please?
i.e. There would only be 1 record for the 2007-09-06 which would have a total of 6.
TIA
Smeat
I have the following sql where I am trying to get the number of records created on each day regardless of the time it was created:
Code:
SELECT
CAST
(
(
STR ( YEAR ( DateCreated ) ) + '/' +
STR ( MONTH ( DateCreated ) ) + '/' +
STR ( DAY ( DateCreated ) )
)
AS DATETIME
)
AS MyAlias,
COUNT(*) AS Total
FROM LMS_ManufacturerPendingLead
WHERE DateCreated BETWEEN '01/15/2007 16:22:56' AND '01/16/2008 09:12:16'
GROUP BY DateCreated
this works fine but gives multiple records for the same date as the time is actually different in the underlying data, see below:
Code:
2007-09-05 00:00:00.000 1
2007-09-06 00:00:00.000 1
2007-09-06 00:00:00.000 1
2007-09-06 00:00:00.000 2
2007-09-06 00:00:00.000 1
2007-09-06 00:00:00.000 1
2007-09-07 00:00:00.000 1
2007-09-11 00:00:00.000 1
If I try to group by the alias I get the following error:
Code:
Msg 207, Level 16, State 1, Line 18
Invalid column name 'MyAlias'.
Can anyone tell me how I can group by the alias so that I get a sum of all records on each date regardless of the time portion of the field please?
i.e. There would only be 1 record for the 2007-09-06 which would have a total of 6.
TIA
Smeat