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 |
|
hueby
Posting Yak Master
127 Posts |
Posted - 2006-04-06 : 17:16:14
|
Hi all,I'm not sure how to phrase this question or search by it, but I have a column named 'price_method_code' that is either 'T' or 'F'. I'm using the code below:SELECT job_number, job_description, project_manager, price_method_code, earned_calc_type FROM JC_Job_Master_MC WHERE (company_code = 'HWP' and status_code = 'A') or (company_code = 'UHP' and status_code = 'A') order by job_number And when 'price_method_code = T' then I want to display "T&M" and when it's equal to 'F' I wanted to display "Lump Sum". Sounds simple enough? Is this code that can be added in the select line? |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2006-04-06 : 17:36:35
|
Yes, what you are looking for is the CASE statement. Something likeSELECT job_number, job_description, project_manager, price_method_code, earned_calc_type, CASE price_method_code WHEN 'T' THEN 'T&M' WHEN 'F' THEN 'Lump Sum' -- optionally put in an ELSE statement ENDFROM ... ---------------------------EmeraldCityDomains.com |
 |
|
|
hueby
Posting Yak Master
127 Posts |
Posted - 2006-04-06 : 17:44:22
|
| Ahhh! I got yeah... thank you! I was unaware of a CASE statement. |
 |
|
|
hueby
Posting Yak Master
127 Posts |
Posted - 2006-04-06 : 17:48:01
|
Can I add a second CASE statement for a differnt row... below is obvioulsy not the correct way.SELECT job_number, job_description, project_manager, CASE price_method_code WHEN 'T' THEN 'T&M' WHEN 'F' THEN 'Lump Sum'END CASE earned_calc_type when 'B' then 'Billed' when 'P' then 'Percentage' ENDFROM |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-04-06 : 17:53:30
|
you missed out the commaSELECT job_number, job_description, project_manager, CASE price_method_code WHEN 'T' THEN 'T&M' WHEN 'F' THEN 'Lump Sum'END , CASE earned_calc_type when 'B' then 'Billed' when 'P' then 'Percentage' ENDFROM KH |
 |
|
|
|
|
|
|
|