Home > Ask the Oracle Experts > SQL Questions & Answers > Use CASE to translate a value to a string
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Use CASE to translate a value to a string

Rudy Limeback EXPERT RESPONSE FROM: Rudy Limeback

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 13 August 2004

Is it possible in SQL to substitute a string if a certain value is returned from a query? For example,

select emp_id from emp_tb

returns

1
2
3

Would it be possible to replace 1 with John and 2 with Mary to give the end result of

John
Mary
3

>
EXPERT RESPONSE

Yes, you can stuff a whole raft [syn: batch, deal, flock, good deal, great deal, hatful, heap, lot, mass, mess, mickle, mint, muckle, peck, pile, plenty, pot, quite a little, sight, slew, spate, stack, tidy sum, wad, whole lot, whole slew] of translations into the SELECT if you wish...

select case emp_id 
            when 1 then 'John'
            when 2 then 'Mary'
            else cast(emp_id as char(4))
        end as emp_string 
  from emp_tb

Note that some database systems may require the CAST, but some don't, and will set the datatype of the CASE expression from the first defined expression inside the CASE.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
SQL
IN list or series of OR conditions?
Connecting tables in a database
SQL query for co-authored books
Querying complex derived tables
SQL string functions
Changing a NULL column to NOT NULL
SQL for hourly totals for the last 48 hours
LEFT OUTER JOIN to a MIN/MAX row
Normalizing a crosstab table
Querying metadata and data at the same time

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2003 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts