|
Posted by Robert Klemme on 10/25/06 11:45
On 25.10.2006 12:37, James Foreman wrote:
> (SQL Server 2000)
>
> I want to aggregate some data from a table, and because I'm going to
> feed the result set into a union, say, I want to put another column on
> there to carry some information that I know will always be the same in
> this particular result set.
>
> Simple example: I have a table DimDate with two columns, date and
> month. I want to bring back a count of how many days there are in the
> current month and the previous month, and I want to use a union to do
> it. [Yes, I *know* there's probably simpler ways to do this with
> datediff functions, etc, but I don't want to give you the real example
> which aggregates lots of columns from a bunch of fact tables, etc etc
> yada yada yada...]
>
> SELECT month, 'This Month' as bespokeColumnHeading, count(*)
> FROM dimDate
> WHERE month = '2006-10-01'
> GROUP BY month, 'This Month';
>
> gives me:
>
> Server: Msg 164, Level 15, State 1, Line 3
> GROUP BY expressions must refer to column names that appear in the
> select list.
Try:
SELECT month, 'This Month' as bespokeColumnHeading, count(*)
FROM dimDate
WHERE month = '2006-10-01'
GROUP BY month;
Kind regards
robert
Navigation:
[Reply to this message]
|