Getting this error: Each GROUP BY expression must contain at least one column that is not an outer reference.
RowId ErrorDatetime ErrorNum ErrorMessage
824 2010-09-24 08:01:42.000 9001 Account 55 not found
823 2010-09-24 08:00:56.000 9001 Account 22222222222 not found
822 2010-09-24 05:06:27.000 9001 Account 55 not found
821 2010-09-24 05:05:42.000 9001 Account 22222222222 not found
I'm trying to get the errormessage, and the first time it occurred for the current day, and that's working because I just do "Group by ErrorMessage".
However, if I want to find the first for each day:
SELECT Min(ErrorDateTime) as 'ErrorDateTime', Min(ErrorMessage) as 'ErrorMessage'
FROM CommonError
WHERE dbo.StripTimeFromDate(ErrorDateTime) = dbo.StripTimeFromDate(getdate())
and ErrorNumber = '9001'
GROUP BY dbo.StripTimeFromDate(getdate()), ErrorMessage
The handy-dandy function (from http://bloggingabout.net/blogs/jschreuder/archive/2007/03/13/useful-t-sql-date-functions.aspx):
ALTER FUNCTION [dbo].[StripTimeFromDate] (@inputDate DATETIME)
RETURNS DATETIME
BEGIN
RETURN DATEADD(d, DATEDIFF(d, 0, @inputDate), 0)
END