or a sub query

SQL Server throws SQL Server error 130 when parameter to an aggregate function is either an expression or a sub query. An aggregate function such as AVG/MAX/COUNT etc. can’t be done on an expression or a sub query. The parameter should be a column name.

Let’s see an example. The below query creates a table and uses an expression as a parameter to MAX function.

The query terminates with below error.

SQL Server error 130

A work around for the same is shown below.

The above query succeeds.


Like us on FaceBook Join the fastest growing SQL Server group on FaceBook

Follow me on TwitterFollow me on FaceBook