SQL Server中的CASE语句不支持OR

不支持语句子句中的OR运算符。我怎样才能做到这一点?WHENCASE


CASE ebv.db_no 

    WHEN 22978 OR 23218 OR 23219 THEN 'WECS 9500' 

    ELSE 'WECS 9520' 

END as wecs_system 


婷婷同学_
浏览 915回答 3
3回答

烙印99

该格式要求您使用以下任一种:CASE ebv.db_no   WHEN 22978 THEN 'WECS 9500'   WHEN 23218 THEN 'WECS 9500'    WHEN 23219 THEN 'WECS 9500'   ELSE 'WECS 9520' END as wecs_system 否则,请使用:CASE    WHEN ebv.db_no IN (22978, 23218, 23219) THEN 'WECS 9500'   ELSE 'WECS 9520' END as wecs_system 

慕妹3242003

CASE  WHEN ebv.db_no = 22978 OR        ebv.db_no = 23218 OR       ebv.db_no = 23219  THEN 'WECS 9500'   ELSE 'WECS 9520' END as wecs_system 

Cats萌萌

您可以使用WHEN拥有的一种表达方式,但不能将两者混合使用。当when_expression是使用简单CASE格式时与input_expression进行比较的简单表达式。when_expression是任何有效的表达式。input_expression和每个when_expression的数据类型必须相同或必须是隐式转换。当Boolean_expression使用搜索的CASE格式时是否评估布尔表达式。Boolean_expression是任何有效的布尔表达式。您可以编程:1。&nbsp; &nbsp; CASE ProductLine&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'R' THEN 'Road'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'M' THEN 'Mountain'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'T' THEN 'Touring'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'S' THEN 'Other sale items'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE 'Not for sale'2。&nbsp; &nbsp; CASE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN ListPrice =&nbsp; 0 THEN 'Mfg item - not for resale'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN ListPrice < 50 THEN 'Under $50'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN ListPrice >= 50 and ListPrice < 250 THEN 'Under $250'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN ListPrice >= 250 and ListPrice < 1000 THEN 'Under $1000'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE 'Over $1000'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END但是无论如何,您都可以预期将使用布尔表达式比较变量排名。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

SQL Server