How to change the value with a select in SQL?

56 views Asked by At

I need to have an other value instead of FULL and NONE but I must do it in the select.

SELECT Calendar_Month,Series,Cnt 
FROM T_Cust_Eom_n 
where TYP='REB'
  and Series='FULL' 
   or TYP='REB' 
  and Series='NONE'  
order by Series desc,Calendar_Month

Can I do this with an as anyhow?

2

There are 2 answers

3
Dev D On BEST ANSWER

Here is what you want:

SELECT Calendar_Month,
CASE WHEN Series = 'FULL'
    THEN 'YOUR_TEXT_FOR_FULL'
     WHEN Series = 'NONE'
    THEN 'YOUR_TEXT_FOR_NONE'
END
AS Series
,Cnt
FROM T_Cust_Eom_n 
WHERE (TYP='REB'and Series='FULL') OR (TYP='REB' and Series='NONE')  ORDER BY Series DESC,Calendar_Month
0
Raging Bull On

Problem:

You should use () when you have multiple conditions in WHERE clause.

Solution:

Improved your query with IN. You can use any other values inside the ():

SELECT Calendar_Month,Series,Cnt 
FROM T_Cust_Eom_n 
where TYP='REB' 
  and Series IN ('FULL','NONE', 'ANOTHER_VALUE')
order by Series desc,Calendar_Month