Skip to content
Advertisement

WHERE CASE WHEN statement with Exists

I am creating a SQL query having WHERE CASE WHEN statement. I am doing something wrong and getting error.

My SQL statement is like

I am getting error as

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

Please help to successfully run query. My logic is to checking for conditional AreaId in (statement) for each row.

I want to select the row only when

  1. company has subscription entry into AreaSubscription for specific area passed by @AreaId
  2. table AreaSubscription does not have subscription entry then evaluate AreaId in (SELECT [@Areas].AreaId FROM @Areas)

Advertisement

Answer

This may help you.

One more solution is

Advertisement