Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
Hi, I have a table like this:

ctrycode countryname fees
uk united kingdom 2.3
uk ch x 3.6

During writing a query what I need as output is to get the countryname for ch x as united kingdom for example

select * from tablename

result should be like this
uk united kingdom 2.3
uk united kingdom 3.6

What I did is like this:

select * from tablname 
where countryname= case when countryname='ch x' then 'United Kingdom'
end 


I am not getting that particular row if I do as the above. Can someone help me out with this?
I am learning on this one, please let me know if I am not clear.
Posted
Updated 28-Feb-11 5:01am
v2

1 solution

You need to ask yourself why you've got 'ch x' in country name if it's supposed to be United Kingdom.

Anyway...do the case statement in your SELECT statement

SQL
select 
    ctrycode, case when countryname='ch x' then 'United Kingdom' ELSE countryname end AS countryname, fees 
from 
    tablname
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 28-Feb-11 11:12am    
And "ch y" then "US"... :-)
My 5.
--SA
makwith9789 28-Feb-11 11:18am    
Thnaks for the solution i got it and as part of countryname i didnt design this table some one did and i got to query this table for something so ,any ways it worked thx for u r time

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900