?
Solved

decode or case statement in oracle query

Posted on 2012-04-11
7
Medium Priority
?
414 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
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 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
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
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

777 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