Sql server SQL Server中的Case语句或条件

Sql server SQL Server中的Case语句或条件,sql-server,tsql,Sql Server,Tsql,或“I”或“E”或“N”中的条件不起作用 有没有别的办法?请建议。不要使用案例。大概是这样的: SELECT * FROM Table1 A INNER JOIN Table2 B ON A.COnfigId = B.COnfigId JOIN Table3 C ON C.TypeId = B.TypeId INNER JOIN Table4 D ON D.ChannelId = B.ChannelId INNER JOIN Table5 E ON E.NoticeId = A.Notice

或“I”或“E”或“N”中的条件不起作用


有没有别的办法?请建议。

不要使用
案例
。大概是这样的:

  SELECT * FROM Table1 A INNER JOIN Table2 B ON A.COnfigId = B.COnfigId JOIN Table3 C ON C.TypeId = B.TypeId INNER JOIN Table4 D ON D.ChannelId = B.ChannelId INNER JOIN Table5 E ON E.NoticeId = A.NoticeId WHERE E.NoticeCode = CASE 
    WHEN (
            D.Channel = 'Post'
            OR (
                D.Channel = 'Email'
                AND C.IsValue = 1
                )
            )
        THEN 'P'
    WHEN (
            (
                D.Channel = 'Email'
                AND C.IsValue = 0
                )
            OR D.Channel = 'Msg'
            )
        THEN 'I'
            OR 'E'
            OR 'N'
    END
                                                                 
其中(a.code='a'和b.code='P')或
(a.code='B'和a.value=1和B.code='P')或
(a.code='B'和a.value 1和B.code in('I','N','E'))

等等,不管你的全部逻辑是什么。

你的查询毫无意义,你也没有在别处解释过。。想想看,如果我让你去商店,说“如果他们有鸡蛋或面包,而且是新鲜烘焙的,那么土豆、胡萝卜或谷类”——这毫无意义
CASE
是T-SQL中的一个表达式(比如
a+b
),它返回一个原子值——不是一块代码,不是一个值的“列表”——只有一个,原子值$QUestion编辑的答案可能有助于澄清如何在
on
子句中使用
case
表达式。
where
子句也是如此。性能可能会受到影响,尽管重新编译提示可能会有所帮助。编辑我的问题。
where (a.code = 'A' and b.code = 'P') or
      (a.code = 'B' and a.value = 1 and b.code = 'P') or
      (a.code = 'B' and a.value <> 1 and b.code in ('I', 'N', 'E'))