Avatar of searchsanjaysharma
searchsanjaysharma
 asked on

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

Avatar of undefined
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

Not working
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
Jim Horn

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.