473,395 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Derived Table and Aggregate Function Not Working Together

I am trying to get this query using a derived table and an aggregate function to work in Excel Query:
Expand|Select|Wrap|Line Numbers
  1. select purordcom.*  from 
  2. (select purOrdDet.PurAcct,
  3. sum(PurOrdDet.ExtCost),PurOrdDet.PONbr from AEMApp.dbo.PurOrdDet PurOrdDet group by PurOrdDet.PurAcct,PurOrdDet.PONbr) as PurOrdCom
But I get a generic error. So I broke it up into two queries - one stripped of the derived table and the other stripped of the aggregate function - to try and isolate the problem:
1.
Expand|Select|Wrap|Line Numbers
  1. select PurOrdCom.* from  (select PurOrdDet.PurAcct,PurOrdDet.ExtCost,PurOrdDet.PONbr from AEMApp.dbo.PurOrdDet PurOrdDet) as PurOrdCom
2.
Expand|Select|Wrap|Line Numbers
  1. select purOrdDet.PurAcct,sum(PurOrdDet.ExtCost),PurOrdDet.PONbr from AEMApp.dbo.PurOrdDet PurOrdDet group by PurOrdDet.PurAcct,PurOrdDet.PONbr
They both worked fine. But when I combine them I get the error again.

Thank you so much!
Aug 21 '13 #1
3 1575
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code.

The problem is that you can't have unaliased column definitions with in a subquery. So the solution is to give it an alias.

But my question is, why bother subquerying the aggregation if you're just going to do a select all against it? It's pointless.
Aug 21 '13 #2
Rabbit,

Got your message on code tags.

Your solution worked.

The query I posted was originally part of a larger query linking this derived table to another table. When it didn't work, I stripped parts of it out to uncover the source of the error.

Thanks again. I can't tell you how frustrated I was with this!
Aug 22 '13 #3
Rabbit
12,516 Expert Mod 8TB
Glad you got it working. Good luck on the rest of your project.
Aug 22 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Claudio Lapidus | last post by:
Hello I would like to know how can I define/create a new aggregate function. I need a custom function that operate on a set of text strings and return a certain string aggregate based on certain...
5
by: Jim | last post by:
Need help with aggregate function...for each unique product, I need the provider with the cheapest cost factor Here't the table (Table1) ID product provider factor 1 123456 abc...
1
by: nfrodsham | last post by:
In Microsoft's help literature, it states: "You can filter out non-unique rows by using the DISTINCT option of an aggregate function" I am trying to do this in Access 2003 with the COUNT...
1
by: Najib Abi Fadel | last post by:
Hi i have an ordered table of dates let's say: 1/1/2004 8/1/2004 15/1/2004 29/1/2004 5/2/2004 12/2/2004
0
by: BillCo | last post by:
just wasted a long time figuring out this and I figure if I post it might save someone some pain! Jet (DAO) will allow you to to use nested aggregate functions like building blocks, e.g.: ...
5
by: BillCo | last post by:
I just wasted a long time figuring out this and I figure if I post it might save someone some pain! Jet (DAO) will allow you to to use nested aggregate functions like building blocks, e.g.: ...
3
by: Aaron | last post by:
I have been searching the boards trying to find an answer to this question and no luck. I am using a query similar to this: Select count(col1) from table1 I was having a hard time accessing...
3
by: ncsthbell | last post by:
I am pulling my hair out on this! Seems like it should be easy, I just can not get it to work like I want. I know I am doing something wrong, so I hope someone can be so kind to guide me!!! I...
7
by: DanicaDear | last post by:
I've tried to put together some code for a form. This code actually compiles (and I've very proud of that!) but it gives me this error when running and points to line 41 in the code below. "Run-time...
10
by: Scorp Scorp | last post by:
Am in the following cenario: Table: tb_test asset and Desc are of text type feilds. ---------------------- prt1 | prt2 | asset | Desc ---------------------- 1 1 11 xxx 2 ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.