An alternative to the case/when
statements seen in other answers is to create a reference table that contains the description of the values (1
/2
/3
).
The biggest advantage of doing it this way is that if this is used in multiple places, you can update all of them at once.
The dbo.curValDesc
table is the reference table you'd need to create/populate. Then your consuming queries can look like the one at the bottom.
create table dbo.existingData
(
rowID int
, curVal tinyint --the column with values of 1/2/3
)
insert into dbo.existingData
values (1, 1)
, (2, 2)
, (3, 3)
, (4, 3)
, (5, 2)
, (6, 1)
, (7, 1)
create table dbo.curValDesc
(
curVal tinyint
, curValDesc varchar(10)
)
insert into dbo.curValDesc
values (1, 'Yes')
, (2, 'No')
, (3, 'Maybe')
select ed.rowID
, cvd.curValDesc
from dbo.existingData as ed
inner join dbo.curValDesc as cvd on ed.curVal = cvd.curVal