select id,
case when oid= 'Winter' then Name else 'noname' end name
,oid
from table1
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi Expert,
the below is the condition
case when oid= 'Winter' then Name else 'noname'
create table table1(id varchar(30), name varchar(30), oid varchar(30))
insert into table1 values('1', 'David', 'Winter')
insert into table1 values('2', 'Hash', 'Winter')
insert into table1 values('3', 'Steve', 'Autumn')
Expected output
('1', 'David', 'Winter')
('2', 'Hash', 'Winter')
('3', 'noname', 'Autumn')
select id,
case when oid= 'Winter' then Name else 'noname' end name
,oid
from table1
Hi @Shambhu Rai ,The case statement syntax should be as follows:
SELECT column1,
column2,
CASE WHEN CONDITION THEN 'Value1'
ELSE 'Value2' END AS columnX
FROM Products
Any other suggestion please
You have been given the correct answer for the sql query. If you are not getting the correct results, then must be more you are not telling us.
Hi @Shambhu Rai, please try this. This is giving expected output. Thanks
SELECT id, CASE id WHEN '3' THEN 'noname' ELSE name END AS name,
CASE id WHEN '3' THEN 'Autumn' ELSE oid END AS oid
FROM table1;