Author |
Topic |
logeshwar
Starting Member
6 Posts |
Posted - 2009-09-03 : 13:37:54
|
as |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-09-04 : 02:13:47
|
tryselect a.division, a.subregion, a.district, a.territory, (select sum(coalesce((case when rp.contractenddate is null then 0 when rp.contractenddate >= w.startdate and rp.contractenddate < w.enddate then 1 else 0 end),0))from rpRepHomeBaseLink yjoin rpt_weeknotodate won w.yearweekno = a.weeknojoin rpContract rpon y.contractid = rp.contractid where y.homebasename = a.territoryand y.startweekno <= a.weeknoand (y.endweekno >= a.weeknoor y.endweekno is null ) ) as terminationsfrom maSalesOfficeView awhere a.weekno between 200901 and 200926group by a.division, a.subregion, a.district, a.territoryorder by 4MadhivananFailing to plan is Planning to fail |
|
|
logeshwar
Starting Member
6 Posts |
Posted - 2009-09-06 : 08:13:58
|
I ma recieving the following error after executing the above said query "Column 'a.WEEKNO' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause". |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-09-06 : 14:06:31
|
whats the purpose of group by here? wont this be enough?select a.division, a.subregion, a.district, a.territory, (select sum(coalesce((case when rp.contractenddate is null then 0 when rp.contractenddate >= w.startdate and rp.contractenddate < w.enddate then 1 else 0 end),0))from rpRepHomeBaseLink yjoin rpt_weeknotodate won w.yearweekno = a.weeknojoin rpContract rpon y.contractid = rp.contractid where y.homebasename = a.territoryand y.startweekno <= a.weeknoand (y.endweekno >= a.weeknoor y.endweekno is null ) )as terminationsfrom maSalesOfficeView awhere a.weekno between 200901 and 200926order by 4 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-09-07 : 10:08:25
|
Can you post the query you used now?MadhivananFailing to plan is Planning to fail |
|
|
logeshwar
Starting Member
6 Posts |
Posted - 2009-09-07 : 11:40:17
|
Hi The second query which you gave worked fine.The first query which you gave had the group by clause.that is why the error ws thrown....Thanks a lot |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-02-05 : 05:32:45
|
What happened to the original post? |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-05 : 06:24:33
|
quote: Originally posted by Kristen What happened to the original post?
OP got answer and dont want to show the actual codeMadhivananFailing to plan is Planning to fail |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-05 : 09:08:33
|
quote: Originally posted by logeshwar Hi The second query which you gave worked fine.The first query which you gave had the group by clause.that is why the error ws thrown....Thanks a lot
thats finebut why did you remove your original post. Please dont do this as it might help somebody in future who might have had same problem |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-05 : 10:06:55
|
Here is the original onehttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=132210I am quoting herequote: I have a DB2 query which needs to be converted to be compliant with SQL Server. The challenge is to work around the Aggregate functioning on subqueried which is not allowed in Sql Server. i run this query and i get the error message ascannot perform aggregate functions on subqueries..Can u help me in the workaroundThe DB2 Query is select a.div, a.subreg, a.dis, a.ter, sum(coalesce((select sum(b.finalcount) from HomeBaseLink xjoin pMW bon b.level = 2and b.weekno = a.weeknoand b.repcontractid = x.contractidwhere x.homebasename = a.terand x.startweekno <= a.weeknoand (x.endweekno > a.weeknoor x.endweekno is null ) ),0))as finalcount,sum(coalesce((select count(distinct z.contractid)from HBL zwhere z.homebasename = a.terand z.startweekno <= a.weeknoand (z.endweekno >= a.weeknoor z.endweekno is null )),0)) as accumulatedcount, sum(coalesce((select sum(coalesce((case when rp.contractenddate is null then 0 when rp.contractenddate >= w.startdate and rp.contractenddate < w.enddate then 1 else 0 end),0))from HBL yjoin rpt_weeknotodate won w.yearweekno = a.weeknojoin rpContract rpon y.contractid = rp.contractid where y.homebasename = a.territoryand y.startweekno <= a.weeknoand (y.endweekno >= a.weeknoor y.endweekno is null ) ),0)) as terminationsfrom maSales awhere a.weekno between 200901 and 200926group by a.div, a.subreg, a.dis, a.terorder by 4;
MadhivananFailing to plan is Planning to fail |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-02-05 : 10:14:59
|
Thanks Madhi |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-05 : 10:16:50
|
quote: Originally posted by Kristen Thanks Madhi
I thought OP may delete that tooThats why I quoted here MadhivananFailing to plan is Planning to fail |
|
|
|