Solved

decode or case statement in oracle query

Posted on 2012-04-11
7
407 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
  • 4
  • 2
7 Comments
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 250 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
Industry Leaders: 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 250 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 69

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle DBLINKS From 11g to 8i 3 67
update using pipeline function 3 34
date show only hh:mm 2 40
Oracle perfomance issue. 4 24
Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
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…
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.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

730 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