CREATE TABLE Test ( EDate Datetime, Code varchar(255), Cdate int, Price int ); insert into Test values('2015-06-19','CL',20150701,12) insert into Test values('2015-06-22','CL',20150701,26) insert into Test values('2015-06-23','CL',20150701,73) insert into Test values('2011-04-08','CL',20110501,97) insert into Test values('2011-04-07','CL',20110501,11) insert into Test values('2011-04-06','CL',20110501,61) insert into Test values('2011-04-08','XP',20110501,37) insert into Test values('2011-04-07','XP',20110501,19) insert into Test values('2011-04-06','XP',20110501,25) insert into Test values('2015-06-19','HO',20150701,92) insert into Test values('2015-06-22','HO',20150701,43) insert into Test values('2015-06-23','HO',20150701,22)
Please refer to the below query. Suppose tomorrow if i decide that Code in('RXP','RXC')statement is not required then i want to remove it from the output. or if i think we need to add another Code like Code in('OHP','OHC') and New Code like 'HO',we want to add it to the output. Is there any anyway to add or delete case statement and change where clause dynamically.
select
[EDate]
,[Code]
,[Cdate]
,[Price],
case when Code in('LOP','LOC') then 'CL'
when Code in('OBP','OBC') then 'RB'
when Code in('RXP','RXC') then 'RX'
else 'NocodeFound' end Code
from test
where Code in('LOP','LOC','OBP','OBC','RXP','RXC')
- Changed type Jingyang LiMicrosoft community contributor, Moderator 12 hours 46 minutes ago