我case
在IN
子句中写了一条声明。我收到以下错误:
子查询返回了1个以上的值。当子查询遵循=,!=,<,<=,>,> =或将子查询用作表达式时,不允许这样做。
这是代码:
declare @Consultant as bigint
set @Consultant=0
select * from tProject where
tProject.ID in
(
Case
When @Consultant=0 then (select #t1.ProjectID from #t1)
else (select #t1.ProjectID from #t1 inner join #t2 on #t1.ProjectID=#t2.ProjectID)
end
)
尝试这个
declare @Consultant as bigint
set @Consultant=0
select * from tProject where
( tProject.ID in (select #t1.ProjectID from #t1) and @Consultant=0)
or
(tProject.ID in
(select #t1.ProjectID from #t1 inner join #t2 on
#t1.ProjectID=#t2.ProjectID) and @Consultant<>0
)
或使用IF
declare @Consultant as bigint
set @Consultant=0
If @Consultant=0 then
select * from tProject where
tProject.ID in (select #t1.ProjectID from #t1)
else
select * from tProject where
tProject.ID in
(select #t1.ProjectID from #t1 inner join #t2 on
#t1.ProjectID=#t2.ProjectID)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句