Skip to content
Advertisement

DB2 (mainframe DB2) – Select sql – CASE WHEN

My data is like this

OUTPUT:

My requirement: If there are more than one CODE, then display CODE as ‘MULTI’, But if there is one CODE, then display that CODE itself (e.g. ‘1A’)

I want my output like below (if the data as above)

CODE AMOUNT MULTI 2.50

If my data is like this:

then I want my output like below:

I tried with below SQL, but it throws error:

Error:

If I hard the both ‘MULTI’ and CODE, then I am getting result.

But I don’t want to hard the ‘SINGLE’

Advertisement

Answer

Try this. If you uncomment the commented out block, you may run this statement as is to check.

Advertisement