2014-10-01 50 views
0
and area.ID in (ISNULL(@area, (select ID from Areas where AreaTypeId = 3))) 

我使用在狀態,以獲取有關指定區域ID信息的參數@area,但如果用戶不跨區域ID的所有信息對所有地區會出現。但我已經運行查詢時出現的錯誤消息:如何返回在SQL Server ISNULL函數不止一個值

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. 

請幫助我,如果你能

回答

0

一個簡單的解決方法是隻在你的子查詢返回@area如果指定了:

and area.ID in (select ISNULL(@area, ID) from Areas where AreaTypeId = 3) 

如果沒有子查詢,您可能會更有效率地做到這一點,但無法確定沒有看到完整的查詢。例如:

select * Area 
    where (@area is not null and area.ID = @area) 
    or (@area is null and area.AreaTypeId = 3)