Solved

Group by cloumn name

Posted on 2011-02-24
5
450 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

766 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