Group by cloumn name

I wrote the following query, and I got error - Invalid column name 'Incdate'.
select Count(*) as 'Amount', datepart(year, incidentdate) as 'Incdate' from MyTable group by Incdate

I changed it to Group by incidentdate, but the reult is not what I want.

What name should I use for the group by?  I need to get the sum amount for individule year.
Thanks.
LVL 1
minglelinchAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Paul JacksonConnect With a Mentor Software EngineerCommented:
try : select Count(*) as 'Amount', datepart(year, incidentdate) as 'Incdate' from MyTable group by datepart(year, incidentdate)
0
 
Paul JacksonSoftware EngineerCommented:
You can't use a column alias in a group by statement unfortunately
0
 
minglelinchAuthor Commented:
What should I use? I cannot use real column name neither as the result is not I want.
0
 
minglelinchAuthor Commented:
Great ! That's the answer. Thanks a lot !
0
 
kelle1Commented:
Change it to this

SELECT COUNT(*) AS 'Amount', DATEPART(year, incidentdate) AS 'Incdate' FROM wv_timecard GROUP BY DATEPART(year, incidentdate)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.