case子句中的case [英] case in where clause
本文介绍了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 ofCASE 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 ofWHERE
expression, not an expression itself.
Seems that entireSELECT
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屋!
查看全文