Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
kt
Yak Posting Veteran
88 Posts |
Posted - 2013-10-30 : 12:05:40
|
Hi,The region table is stored the values for:regionName============UNITED STATES2 INDIA3HONG KONG14if regionName has the value as #, then I want to replace that number with the name, else just keep the name (UNITED STATES,INDIA,HONG KONG) select [customer],case regionName when 1 then 'Asia Pacific' when 2 then 'Europe, Middle East, & Africa' when 3 then 'North America' when 4 then 'South America' else regionName END AS regionfrom [dbo].[region]thanks |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-10-30 : 12:27:47
|
quote: Originally posted by kt Hi,The region table is stored the values for:regionName============UNITED STATES2 INDIA3HONG KONG14if regionName has the value as #, then I want to replace that number with the name, else just keep the name (UNITED STATES,INDIA,HONG KONG) select [customer],case regionName when 1 then 'Asia Pacific' when 2 then 'Europe, Middle East, & Africa' when 3 then 'North America' when 4 then 'South America' else regionName END AS regionfrom [dbo].[region]thanks
Is that query not working? If not, try this:SELECT [customer] , CASE WHEN regionName = '1' THEN 'Asia Pacific' WHEN regionName = '2' THEN 'Europe, Middle East, & Africa' WHEN regionName = '3' THEN 'North America' WHEN regionName = '4' THEN 'South America' ELSE regionName END AS regionFROM [dbo].[region] |
 |
|
Grifter
Constraint Violating Yak Guru
274 Posts |
Posted - 2013-10-30 : 12:40:08
|
I replicated that and it appeared to work:select case t.Region when '1' then 'Asia Pacific'when '2' then 'Europe, Middle East, & Africa'when '3' then 'North America'when '4' then 'South America'else t.Regionend as regionfrom TempRegion t region=============================UNITED STATESEurope, Middle East, & AfricaINDIANorth AmericaHONG KONGAsia PacificSouth America |
 |
|
kt
Yak Posting Veteran
88 Posts |
Posted - 2013-10-30 : 13:40:59
|
worked, thanks all !!!! |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2013-10-31 : 03:00:43
|
If there are more number of regions, you can have a mapping table with region codes and names and join with source table to get the namesMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|