Skip to content
Advertisement

A function that returns different column values based on input

Here is a table FRUITS

Is it possible to create a function that returns column A for apple (0), B for Orange(4) and C for Apricot(8)?

Right now I have a function like this

This function returns the column name, but not the actual value.

Advertisement

Answer

Create a view!

Then, use the view for the queries in your package.

You can also add the column as a computed column directly into the table:

With this approach, the column looks like it is part of the table.

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