Solved

decode or case statement in oracle query

Posted on 2012-04-11
7
411 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 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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 70

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

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!

Question has a verified solution.

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

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
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 video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

695 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