?
Solved

PL-SQL query help

Posted on 2012-09-14
4
Medium Priority
?
549 Views
Last Modified: 2012-09-30
Hi experts, need help with basic pl-sql query which is new to me..

i have attached the script. this is to calcuate aht from 3 different dynamic variable..

@aht = @att + @ht + @acw

Any response appreciated
aht.txt
0
Comment
Question by:parpaa
  • 2
  • 2
4 Comments
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 38399359
Keeping with your logic try this:
declare 

   acw number(5);
   ht number(5);
   att number(5);
    aht number;
begin

select sum(customer_acw_duration) into acw from interaction_resource_fact f inner join Resource_ r 
on f.resource_key = r.resource_key inner join technical_descriptor t on f.technical_descriptor_key = t.technical_descriptor_key 
where r.resource_name = 'schristensen' and t.technical_result_code = 'DIVERTED' and t.result_reason_code = 'ANSWEREDBYAGENT' 
or t.result_reason_code = 'UNSPECIFIED';

select sum(customer_hold_duration) into ht from interaction_resource_fact f inner join Resource_ r 
on f.resource_key = r.resource_key inner join technical_descriptor t on f.technical_descriptor_key = t.technical_descriptor_key 
where r.resource_name = 'schristensen' and t.technical_result_code = 'DIVERTED' and t.result_reason_code = 'ANSWEREDBYAGENT' or t.result_reason_code = 'UNSPECIFIED'
and f.customer_handle_count > 0;

select sum(talk_duration) into att from interaction_resource_fact f inner join Resource_ r 
on f.resource_key = r.resource_key inner join technical_descriptor t on f.technical_descriptor_key = t.technical_descriptor_key 
where r.resource_name = 'schristensen' and t.technical_result_code = 'DIVERTED' and t.result_reason_code = 'ANSWEREDBYAGENT' or t.result_reason_code = 'UNSPECIFIED'
and f.customer_handle_count > 0;

aht := acw+ht+att;

end;
/

Open in new window



Now why not do it all at once?

declare 
    aht number;
begin


select sum(customer_acw_duration+customer_hold_duration+talk_duration) into aht from interaction_resource_fact f inner join Resource_ r 
on f.resource_key = r.resource_key inner join technical_descriptor t on f.technical_descriptor_key = t.technical_descriptor_key 
where r.resource_name = 'schristensen' and t.technical_result_code = 'DIVERTED' and t.result_reason_code = 'ANSWEREDBYAGENT' 
or t.result_reason_code = 'UNSPECIFIED';
end;
/

Open in new window

0
 

Author Comment

by:parpaa
ID: 38399415
awesome, i tried the earlier query you gave but missed 'into' and also 'aht := ' can i now dynamically call the agent_id too? like where @agent_id = ' ' ?
0
 

Author Comment

by:parpaa
ID: 38399542
i get null for the total sum for aht. when i run individually i am getting counts. anything we are amissing?
0
 
LVL 78

Accepted Solution

by:
slightwv (䄆 Netminder) earned 1200 total points
ID: 38399675
>>i get null for the total sum for aht

You must have some null values in one of the columns.  In Oracle if you do anything with a null, like add it to some number, you get a null.

use the NVL function to get around it:

select sum(nvl(customer_acw_duration,0)+nvl(customer_hold_duration,0)+nvl(talk_duration,0)) into aht
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

850 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