简体   繁体   English

具有多个IS NULL条件的CASE WHEN语句

[英]CASE WHEN statement with multiple IS NULL conditions

I have 3 variables(sedol, cusip, isin). 我有3个变量(sedol,cusip,isin)。 I want the to pull in the SEDOL if it is available, if not then pull in CUSIP. 我希望拉入SEDOL(如果可用),否则请拉入CUSIP。 If CUSIP is also unavailable then pull in ISIN. 如果CUSIP也不可用,则输入ISIN。

Below is the code I've written. 以下是我编写的代码。 The problem is that when CUSIP and SEDOL is unavailable it does not pull in the ISIN. 问题是当CUSIP和SEDOL不可用时,它不会拉入ISIN。 I can't figure out where I may have missed something. 我不知道我可能错过了什么。

CASE
WHEN sedol IS NULL THEN cusip
WHEN cusip IS NULL AND sedol is NULL THEN isin

ELSE sedol
END

Appreciate the help! 感谢帮助!

The order of your operations are preventing the 2nd when condition from ever being executed. 您的操作顺序阻止了条件第二次执行。 You would need to swap the when conditions. 您将需要交换when条件。

You want to look into the coalesce function. 您想研究coalesce功能。

尝试这个:

COALESCE(SEDOL, CUSIP, ISIN)

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

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