Solved

decode or case statement in oracle query

Posted on 2012-04-11
7
399 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 76

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 76

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 68

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

929 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now