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
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
ASKER
How to display other fields also, Like i have other fields as UID,State,District and mode with above scenario.
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.