How to do repalcement of values in sql query in output using select
I have a field id and mode in table.
It can contain values 1 2 3 4 and null.
I want when the mode is 1 the output data should show Monovalent,
for 2 it should show bivalent for 3 it should show referral and 4 it should show slide
In other words it want to do replace in query with these words
Microsoft SQL Server 2008
Last Comment
Jim Horn
8/22/2022 - Mon
Jim Horn
SELECT CASE mode
WHEN 1 THEN 'Monovalent'
WHEN 2 THEN 'bivalent'
WHEN 3 THEN 'referral'
WHEN 4 THEN 'slide' END as name_goes_here
FROM your_table
Also if you want a good read on CASE blocks, the article SQL Server CASE Solutions is a very good demo of the multiple ways to use CASE.
searchsanjaysharma
ASKER
How to display other fields also, Like i have other fields as UID,State,District and mode with above scenario.
searchsanjaysharma
ASKER
SELECT uin,village, CASE
WHEN mode 0 THEN ''
WHEN mode 1 then 'Monovalent'
WHEN mode 2 then 'Bivalent'
WHEN mode 3 then 'Referral'
WHEN mode 4 then 'Slide'
WHEN mode null then 'Slide'
END as mode
FROM mstm1
WHEN 1 THEN 'Monovalent'
WHEN 2 THEN 'bivalent'
WHEN 3 THEN 'referral'
WHEN 4 THEN 'slide' END as name_goes_here
FROM your_table
Also if you want a good read on CASE blocks, the article SQL Server CASE Solutions is a very good demo of the multiple ways to use CASE.