We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

SQL Server Compute Statement

Medium Priority
329 Views
Last Modified: 2012-05-06
The COMPUTE statement in this sproc gives me the following error when I attempt to save it in design mode.
Compute Clause #1, aggregate expression #1 is not in the select list

Can anyone tell me why? My objective is to get a sum of the GB and TB columns from the select statement as grand totals for all derivatives.
Thank you... Herb
SELECT DerivativeType , COUNT(DerivativeKey) AS DerivativeCount, SUM(GB) AS GB, SUM(TB) AS TB 
FROM Derivatives 
WHERE ShipmentKey = @ShipmentKey AND QCPerson = 0
GROUP BY DerivativeType
COMPUTE COUNT(DerivativeKey), SUM(GB), SUM(TB)

Open in new window

Comment
Watch Question

Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009
Commented:
try this instead:
SELECT DerivativeType , COUNT(DerivativeKey) AS DerivativeCount, SUM(GB) AS GB, SUM(TB) AS TB 
FROM Derivatives 
WHERE ShipmentKey = @ShipmentKey AND QCPerson = 0
GROUP BY DerivativeType
WITH ROLLUP

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanks a bunch. That worked like a charm!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.