Skip to content
Advertisement

passing a parameter to a function; Subquery returned more than 1 value. This is not permitted

I want the function to return age of the employee in specified date passed to the function by parameter

When I try to do it without the function it works perfectly fine

But if I pass the date parameter to a function I get this error:

Msg 512, Level 16, State 1, Line 12
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

Advertisement

Answer

I want the function to return age of the employee in specified date passed to the function by parameter

The key here is the employee. The code that works would be clearer if you wrote:

You need to pass both values in:

Or perhaps identify the employee:

You would call this version as:

Alternatively, you could create an inline table-valued function that returns the age for all employees as of that date:

This would be called as:

In a table-valued inline function in many ways acts like a parameterized view.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement