每个案例多个记录

时间:2016-02-09 11:43:19

标签: sql

我试图创建这样的查询:

select *
from ...
stageid IN  (CASE WHEN o.someotherId= (@predefinedId) 
                            THEN (N'here is guid actually',N'another guid') 
                            ELSE (N'and here is a guid',N'+ guid')
                       END)

它没有编译,但如果我每个案例只留下1个guid,它就会编译但不会解决我的任务。

每个案例可以做些什么来返回多个记录?

2 个答案:

答案 0 :(得分:1)

我想你希望这样做:

where (o.someotherId = (@predefinedId) and stageid IN (...))
    or (o.someotherId != (@predefinedId) and stageid IN (...))

答案 1 :(得分:0)

使用OR代替CASE

... (
    (o.someotherId = (@predefinedId) AND stageid IN (N'here is guid actually',N'another guid')) OR
    (o.someotherId <> (@predefinedId) AND stageid IN (N'and here is a guid',N'+ guid'))
)