Solved

Group by cloumn name

Posted on 2011-02-24
5
424 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:minglelinch
  • 2
  • 2
5 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34974881
You can't use a column alias in a group by statement unfortunately
0
 
LVL 1

Author Comment

by:minglelinch
ID: 34974903
What should I use? I cannot use real column name neither as the result is not I want.
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
ID: 34974961
try : select Count(*) as 'Amount', datepart(year, incidentdate) as 'Incdate' from MyTable group by datepart(year, incidentdate)
0
 
LVL 1

Author Comment

by:minglelinch
ID: 34975003
Great ! That's the answer. Thanks a lot !
0
 
LVL 4

Expert Comment

by:kelle1
ID: 34975011
Change it to this

SELECT COUNT(*) AS 'Amount', DATEPART(year, incidentdate) AS 'Incdate' FROM wv_timecard GROUP BY DATEPART(year, incidentdate)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now