x

Cannot perform an aggregate function on an expression containing an aggregate or a subquery

max(case when datediff(YY,max(birth_date1),getdate()) > 18 then dep_first_name1 else 0 end) maj_dep_first_name

When I run my procedure with the above statement I get teh error: Cannot perform an aggregate function on an expression containing an aggregate or a subquery.

Any help is appreciated.
Thanks
RTSFO

more ▼

asked Dec 04 '09 at 08:49 PM in Default

RTSFO gravatar image

RTSFO
1 1 1 1

(comments are locked)
10|1200 characters needed characters left

1 answer: sort oldest

you have a max() within another max()

try removing the outer max()

case when datediff(YY,max(birth_date1),getdate()) > 18 then dep_first_name1 else 0 end            

if does not work, please post your full query

more ▼

answered Dec 04 '09 at 11:29 PM

Squirrel 1 gravatar image

Squirrel 1
1.6k 1 3

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1933
x57

asked: Dec 04 '09 at 08:49 PM

Seen: 2268 times

Last Updated: Dec 05 '09 at 08:27 AM