Skip to content
Advertisement

Multiple WHEN in CASE only applies first two

I have a CASE with 4 WHENs. The first two applie fine, but the last two (or any others I add past that) do not get applied. All WHENs are referring to the same field.

Here’s what I’m trying to do. The field in question is formatted as:

So it would look like

The first Case I wrote was to eliminate the date

That works great. Then I want to remove the Index Name so I added a second WHEN. That worked also. But then, our company will have the full legal name of the company we’re doing business (so “Wal-Mart Stores, Inc” or “The Walt Disney Company”. For readability, I want those records to just say “WalMart” or Disney.”

My new code reads as

I don’t understand why this stops working after the first two. At first I thought maybe it’s because they are all referring to the first column, but then the second WHEN wouldn’t have worked either.

Anyone know what’s going on?

Advertisement

Answer

If you want to do all the replacements rather than just the first one:

A case expression stops at the first expression that evaluates to true.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement