If they want only one state, you can, as other people point out, simply translate null:
SELECT COALESCE(thecolumn1,'N/A') AS mycolumnalias
IF it is found that they really want to have a “three-state” in the column, you can create a VARCHAR column for the companion.
SELECT COALESCE(thecolumn1, companioncolumn1,'N/A') AS mycolumnalias
Benefits:
- If they change their minds again, you can change the value of companioncolumn1.
- If you use both columns in COALESCE, it automatically gets the first column when it is not null, gets the value of the companion object if it is set, and the first is null, and has a backup of "N / A" specified in select.
- You can manage it at the database level.
- You save the data type of the source column
Disadvantages:
- Has an additional column in the database for management.
- Somewhat more complex SELECT statements
- You need to manage this at the database level.
- Listing and type validation will be more complex, but you already have this problem.
source share