I assume you mean that you try to add fields that are not part of the GROUP
By statement. This is not allowed, since there may be multiple different
values. Consider the following table of data
Col1 Col2
1 1
1 2
1 3
SELECT Col1, Count(*)
FROM table
GROUP BY col
If you group by 1, you only get one row. However, if you tried to put Col2
in the output, there are three different values. You could use Min() or
Max() to output one of the rows, but that is probably not what you want.
--
----------------------------------------------------------------------------
-----------
Louis Davidson (drsql@hotmail.com)
Compass Technology Management
Pro SQL Server 2000 Database Design
http://www.apress.com/book/bookDisplay.html?bID=266 [quoted text, click to view] "john smith" <dwinre2000@yahoo.com> wrote in message
news:bkdndo$5nn0$1@news3.infoave.net...
> I am trying to get a query to work using grouping by days
>
> SELECT CAST(datepart(dd,date_created) AS int) AS DOW, SUM(prod_unique) as
> unique_count, COUNT(prod_id) as total_hits,
> (COUNT(prod_id) - SUM(prod_unique)) AS total_returns
> FROM crm_ecom_tracker
> WHERE datepart(yyyy,date_created) = @spYear AND datepart(m,date_created) =
> @spMonth AND org_id = @spOrg_id and prod_id = @spProd_id
> GROUP BY CAST(datepart(dd,date_created) AS int)
> ORDER BY CAST(datepart(dd,date_created) AS int) DESC
>
>
> RETURN @@ROWCOUNT
>
> The problem is when i try to add generic fields i get the field is invalid
> because it is not an aggregate function. Since it is a tracking query the
> results need to be grouped by the day of the week.
>
> Thanks for any help,
> Donnie
>
>