Skip to content
Advertisement

Subquery Returns Muiltiple Values, but I am using “IN” as my operator

Long story short, I have a Crosswalk table that has a column name MgrFilterRacf. There is a single line in the table I use to reference various things across a few queries, this method has worked fine for me. However, when I had to reference more than one value it gives me the error below. I am really at a loss as to why it is not working. I see a TON of topics/posts on this, but most are solutions stating to use the IN operator, which I already am. The mildly infuriating thing is that it works when I only call one value and delete the second line on the crosswalk table regardless of “In” or “=” being used.

Error for reference:

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

Crosswalk table format:

Query:

Specific offending lines of code:

Advertisement

Answer

It’s not the IN clause that’s causing the error, since IN doesn’t have to return only 1 value. Instead it’s likely here:

CASE ... < (Select AttFloorScore from tblAvs1Scoring)

Try select count(AttFloorScore) from tblAvs1Scoring and see if it’s > 1. I am sure it is.

This can be mitigated by what ever method is appropriate for your data.

  1. Using TOP 1
  2. Using an aggregate like MAX()
  3. Correlating the sub-query to limit the rows returned.
  4. Using the appropriate WHERE clause
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement