Re: Tircky, but simple aggregate function question

Tech-Archive recommends: Fix windows errors by optimizing your registry



just for information, some SQL engines accepts group by with the position number in the select of the field you want starting at 1 but i don't if SQL Server does

for your example: group by 1 works with them

/Il se trouve que _Opa_ a tapoté/ :
This works. Thanks!
I knew it was simple for someone.

"Faust" wrote:

and did you tried: group by DatePart(yyyy,wo.DateIssued) ?

/_Opa_ a émis l'idée suivante/ :
Hi,

I have a table, "WorkOrders", containing a date field used in a group by
and a another field whose values I am adding. SELECT DatePart(yyyy,wo.DateIssued) AS YearPaid, SUM(wo.EstManHours)AS SumEstHours
FROM WorkOrders wo
GROUP BY wo.DateIssued

The problem is that I don't get a grouping by year, becase the DateIssued field
contains the month, day, and time information. I get the following

YearPaid, SumEstHours
---------------------------
2003 4000
2003 2000
2004 1000
2004 1500

I really want 2003 | 6000 and 2004 | 2500, I tried using the alias YearPaid in the groupby, but got an error. Any ideas on how this is done?

Thanks in advance

--
Faust
"Une âme en peine peut en cacher une autre"


--
*/Teträm/*
http://www.tetram.org

"Fous-y sur la gueule, ça te mettra de bonne humeur" - Proverbe Troll


.