Group By on Derived Field

PeterErhard
PeterErhard used Ask the Experts™
on
I've got the following query:
      
select
      datename(month,log_date) + ' ' + datename(year,log_date) as CalcDate,
      COUNT(*)
from
      logging
group by
      CalcDate
      
When I try to run it however, I get:

Msg 207, Level 16, State 1, Line 4
Invalid column name 'CalcDate'.

How am I able to group by CalcDate to get my desired result?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
Put the aggregate in the GROUP BY:

select 
      datename(month,log_date) + ' ' + datename(year,log_date) as CalcDate, 
      COUNT(*)
from 
      logging
group by 
      datename(month,log_date) + ' ' + datename(year,log_date)

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial