case子句中的case [英] case in where clause

查看:114
本文介绍了case子句中的case的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 选择  distinct  po.publisher_code  FROM  PurchaseOrder采购订单( NOLOCK ),
发布商p( nolock WHERE
po.Status = ' Pe'
CASE (po.PublisherCode)
< span class =code-keyword> WHEN ' 0' THEN po.PublisherCode * = p.Publisher_Code end
何时<> ' 0' 然后 po.PublisherCode = p.Publisher_Code end
po.POId = 464839





它给了我:'='附近的语法不正确错误

解决方案

CASE WHEN 指令的正确陈述在此处: CASE(Transact-SQL) [ ^ ]



它应该是这样的:

  WHERE   CASE (po.SomeField) WHEN  '  SomeValue' 那么 '  OtherValue'  ELSE  '  AnotherValue'  END  



它必须是 WHERE 表达式的一部分,而不是表达式本身。



似乎整个 SELECT 语句是错误的,除非您想要交叉连接两个表。在任何其他情况下,您必须阅读: SQL连接的可视化表示 [ ^ ]


select distinct po.publisher_code FROM PurchaseOrder PO (NOLOCK),             
Publisher p(nolock) WHERE 
 po.Status = 'Pe'   
  and  CASE (po.PublisherCode)
                WHEN '0' THEN po.PublisherCode *= p.Publisher_Code end 
                when <>'0' then po.PublisherCode = p.Publisher_Code end 
   and po.POId =464839



it is giving me: Incorrect syntax near '=' error

解决方案

A proper statement of CASE WHEN instruction is here: CASE (Transact-SQL)[^]

It should be something like that:

WHERE CASE (po.SomeField) WHEN 'SomeValue' THEN 'OtherValue' ELSE 'AnotherValue' END


It must be the part of WHERE expression, not an expression itself.

Seems that entire SELECT statement is wrong, unless you wanted to cross join both tables. In any other cases, you have to read about: Visual Representation of SQL Joins[^]


这篇关于case子句中的case的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆