简体   繁体   English

案例,然后(返回列)否则结束

[英]CASE WHEN THEN (Return Column) ELSE END

I'm very new to SQL and mainly use Excel, I am using Oracle BI and need to add a column that does the following. 我是SQL的新手,主要使用Excel,我使用的是Oracle BI,需要添加一列来完成以下操作。

=IF(A1="EG123456",B1,"")

I've got this far. 我已经走了这么远。

CASE WHEN "table1"."clientnumber" = 'EG123456' 
THEN "table1"."BookingID" 
ELSE '' 
END

it accepts the formula but when I go to view the results it says "View Display Error" 它接受公式,但是当我去查看结果时,它说“查看显示错误”

It seems likely that BookingID might be a type other than CHAR/VARCHAR; BookingID可能是CHAR / VARCHAR以外的其他类型; for example perhaps it's a numeric field? 例如,也许这是一个数字字段? All possible returns form a CASE must be of compatible type. CASE的所有可能退货必须为兼容类型。

Would it work to use ELSE NULL instead of ELSE '' ? 使用ELSE NULL代替ELSE ''是否可行? NULL will be compatible with all types and will come across as "blank"; NULL将与所有类型兼容,并将以“空白”出现; but depending on how you further process the results, you may need to beware of the "strange" rules for handling NULL values. 但是根据您进一步处理结果的方式,可能需要提防处理NULL值的“奇怪”规则。

The other option might be to cast BookingID to a CHAR type. 另一个选项可能是将BookingID强制转换为CHAR类型。 eg if you know that it's never more than 20 characters, you could say THEN CAST(BookingID AS CHAR(20)) 例如,如果您知道它永远不会超过20个字符,则可以说THEN CAST(BookingID AS CHAR(20))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM