简体   繁体   中英

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.

=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; for example perhaps it's a numeric field? All possible returns form a CASE must be of compatible type.

Would it work to use ELSE NULL instead of ELSE '' ? NULL will be compatible with all types and will come across as "blank"; but depending on how you further process the results, you may need to beware of the "strange" rules for handling NULL values.

The other option might be to cast BookingID to a CHAR type. eg if you know that it's never more than 20 characters, you could say THEN CAST(BookingID AS CHAR(20))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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