Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

decode or case statement in oracle query

Posted on 2012-04-11
7
Medium Priority
?
420 Views
Last Modified: 2012-04-11
I have a view

create or replace view off_duty (site_code,
                                 site_code1,
                                 department_id,                                                 department_name,
                                 schedule_date,                                                 start_time,                                                 start_ampm,
                                 end_time,                                                 end_ampm,                                                 total_hours,
                                 short_description,                                                 reason_code,                                                 payroll_id,                                                 emp_name,                                                 mail_last_name,                                                 ss_mob)
             as
select d.site_code,ds.site_code,eu.department_id,d.department_name,
       ds.schedule_date,ds.start_time,ds.start_ampm,
       ds.end_time,ds.end_ampm,ds.total_hours,
       nar.short_description,nar.reason_code,
         ds.payroll_id,FIRST_NAME||' '||MAIL_LAST_NAME,
         mail_last_name,d.ss_mob
  from emp_unexcld eu,
       department d,
       dept_staff ds,
       not_avail_reason nar
where eu.payroll_id = ds.payroll_id
  and ds.department_id = d.department_id(+)
  and ds.reason_code = nar.reason_code  
  and nar.schedule_required_flag = 'Y'
-----------------------------------
If department_id in (5,95) then I have to get ds.site_code else d.site_code
0
Comment
Question by:anumoses
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 1000 total points
ID: 37832570
case when department_id in (5,95) then ds.site_code else d.site_code end
0
 
LVL 6

Author Comment

by:anumoses
ID: 37832588
sorry

select site_code,site_code1 from
off_duty
where payroll_id = 'ZZW0024100'
AND SCHEDULE_DATE between '09-apr-2012' and '12-apr-2012'

----------------

SITE_CODE|SITE_CODE1
AU01|MC31
AU01|CS28
EL01|
EL01|

If Site_code1 is not null then take site_code1 elseif site_code1 is null then get site_code
0
 
LVL 6

Author Comment

by:anumoses
ID: 37832598
select schedule_date,site_code,site_code1 from
off_duty
where payroll_id = 'ZZW0024100'
AND SCHEDULE_DATE between '09-apr-2012' and '12-apr-2012'

------------------

SCHEDULE_DATE|SITE_CODE|SITE_CODE1
4/12/2012|AU01|MC31
4/11/2012|AU01|CS28
4/10/2012|EL01|
4/9/2012|EL01|
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Author Comment

by:anumoses
ID: 37832618
select a.emp_name,
       to_char(schedule_date,'fmDy')WEED_DAY,
       schedule_date,
         replace(to_char(a.start_time/100, 'fm00.00'), '.', ':')||a.start_ampm start_time,
         replace(to_char(a.end_time/100, 'fm00.00'), '.', ':')||a.end_ampm end_time,
         to_char(a.total_hours/100, 'fm00.00') total_hours,
       a.short_description,
         a.department_name,
         s.city_name,a.ss_mob
  from off_duty a, blood_drives bd,sites s,dept_sched des
 where a.site_code = s.site_code(+)
   and a.schedule_date = bd.drive_date(+)
   and a.site_code = bd.site_code(+)
   and des.department_id = a.department_id
   and a.schedule_date between trunc(sysdate,'d') and last_sched_date
-------------------

This is my final report query. So may be we want to add the site code here, with the logic that I need.
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 1000 total points
ID: 37832619
>>If Site_code1 is not null then take site_code1 elseif site_code1 is null then get site_code

This is a completely different requirement than the question asked.

If you asked the wrong question, I suggest you close this one and ask the correct one.

Anyway, once you understand the CASE statement logic, writing the statement is pretty straight forward.

Can you not use the similar is null login from your other question to figure out this one?

http://www.experts-exchange.com/Database/Oracle/Q_27668956.html
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 37832620
Use   @NVL(site_code1, site_code)
0
 
LVL 6

Author Closing Comment

by:anumoses
ID: 37832642
thanks
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example, show how to take different types of Oracle backups using RMAN.

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question