select id,status
from request
The status column of the above query returns some integer values. I need to put a condition to return some strings values instead of the integer values.
eg: if the status 1 then it should return “New” or if the status is 2 then it should return “Approved”.
I despise mysterious integer values stored in a table with no clue as to their meaning.
My solution will take a bit more work up front, but it is well worth it in the long run.
Start by creating a new table of StatusValues:
Populate that table:
Create a foreign key relationship from the Request table to this one:
And finally, write the query:
The previously mysterious
request.statuscolumn is now well documented and managed within the database.