Hi,
I have the different data requested attached as text files. I did not paste them into the post as they are lengthy. However, below is the sql I'm using. Your help is greatly appreciated.
SELECT
STREAM_ID,
STREAMROW,
EVENTBEGINDATE,
EVENTBEGINTIME,
EVENTTIME,
sum(coalesce(EVENTFINALAMOUNT,0.00)),
sum(coalesce(QUANTITY,0.00)),
cast(replace(CALLINGNUMBER, '+', '') as char(20)),
Case
when gcalledprefix_id is not null and gconnectedprefix_id is not null and gcalledprefix_id != gconnectedprefix_id
then cast(replace(CONNECTEDNUMBER, '+', '') as char(20))
else cast(replace(CALLEDNUMBER, '+', '') as char(20))
End,
gcallingprefix_id,
Case
when gcalledprefix_id is not null and gconnectedprefix_id is not null and gcalledprefix_id != gconnectedprefix_id
then gconnectedprefix_id
when gcalledprefix_id is not null then gcalledprefix_id
else gconnectedprefix_id
End,
EVENTCLASS_ID,
TARIFFPLANVARIANT_ID,
substr(accountnumber,1,20)
TYTAN_ACT_TP,
(select distinct calendarclass
from tytan.post_pstn usg2
where usg2.eventbegindate = usg.eventbegindate and
usg2.stream_id = usg.stream_id and
usg2.streamrow=usg.streamrow and
entrytype = 'P' and usg2.resultmessage_id is null) Calendar,
GUIDINGCPARTY_ID,
GUIDINGCPACCOUNT_ID,
GUIDINGAPNAME_ID,
GUIDINGCITEM_ID,
(select coalesce(sum(usg2.chargetime),0.00)
from tytan.post_pstn usg2
where usg2.eventbegindate = usg.eventbegindate and
usg2.stream_id = usg.stream_id and
usg2.streamrow = usg.streamrow and
usg2.calendarclass = 1 and
usg2.resultmessage_id is null and
usg2.quantity is not null) Peak_Act_Minutes,
(select coalesce(sum(usg2.quantity),0.00)
from tytan.post_pstn usg2
where usg2.eventbegindate = usg.eventbegindate and
usg2.stream_id = usg.stream_id and
usg2.streamrow = usg.streamrow and
usg2.calendarclass = 1 and
usg2.resultmessage_id is null) Peak_Bill_Minutes,
(select coalesce(sum(usg2.chargetime),0.00)
from tytan.post_pstn usg2
where usg2.eventbegindate = usg.eventbegindate and
usg2.stream_id = usg.stream_id and
usg2.streamrow = usg.streamrow and
usg2.calendarclass = 2 and
usg2.resultmessage_id is null and
usg2.quantity is not null) OPeak_Act_Minutes,
(select coalesce(sum(usg2.quantity),0.00)
from tytan.post_pstn usg2
where usg2.eventbegindate = usg.eventbegindate and
usg2.calendarclass = 2 and
usg2.resultmessage_id is null and
usg2.stream_id = usg.stream_id and
usg2.streamrow = usg.streamrow) OPeak_Bill_Minutes,
(select coalesce(sum(usg2.chargefinalpricingamount),0.00)
from tytan.post_pstn usg2
where usg2.eventbegindate = usg.eventbegindate and
usg2.stream_id = usg.stream_id and
usg2.streamrow = usg.streamrow and
usg2.calendarclass = 1 and
usg2.resultmessage_id is null) Peak_Charge,
(select coalesce(sum(usg2.chargefinalpricingamount),0.00)
from tytan.post_pstn usg2
where usg2.eventbegindate = usg.eventbegindate and
usg2.stream_id = usg.stream_id and
usg2.streamrow = usg.streamrow and
usg2.calendarclass = 2 and
usg2.resultmessage_id is null) OPeak_Charge,
(select coalesce(sum(usg2.chargetime),0.00)
from tytan.post_pstn usg2
where usg2.eventbegindate = usg.eventbegindate and
usg2.stream_id = usg.stream_id and
usg2.streamrow = usg.streamrow and
usg2.segmentclass_id = 5 and
usg2.resultmessage_id is null) Seg1_Act_Minutes,
(select coalesce(sum(usg2.quantity),0.00)
from tytan.post_pstn usg2
where usg2.eventbegindate = usg.eventbegindate and
usg2.stream_id = usg.stream_id and
usg2.streamrow = usg.streamrow and
usg2.segmentclass_id = 5 and
usg2.resultmessage_id is null) Seg1_Bill_Minutes,
(select coalesce(sum(usg2.eventfinalamount),0.00)
from tytan.post_pstn usg2
where usg2.eventbegindate = usg.eventbegindate and
usg2.stream_id = usg.stream_id and
usg2.streamrow = usg.streamrow and
usg2.segmentclass_id = 5 and
usg2.resultmessage_id is null) Seg1_Charge,
(select coalesce(sum(usg2.chargetime),0.00)
from tytan.post_pstn usg2
where usg2.eventbegindate = usg.eventbegindate and
usg2.stream_id = usg.stream_id and
usg2.streamrow = usg.streamrow and
usg2.segmentclass_id = 4 and
usg2.resultmessage_id is null) Seg2_Act_Minutes,
(select coalesce(sum(usg2.quantity),0.00)
from tytan.post_pstn usg2
where usg2.eventbegindate = usg.eventbegindate and
usg2.stream_id = usg.stream_id and
usg2.streamrow = usg.streamrow and
usg2.segmentclass_id = 4 and
usg2.resultmessage_id is null) Seg2_Bill_Minutes,
(select coalesce(sum(usg2.eventfinalamount),0.00)
from tytan.post_pstn usg2
where usg2.eventbegindate = usg.eventbegindate and
usg2.stream_id = usg.stream_id and
usg2.streamrow = usg.streamrow and
usg2.segmentclass_id = 4 and
usg2.resultmessage_id is null) Seg2_Charge,
timestamp(char(usg.eventbegindate), char(usg.eventbegintime))
FROM
tytan.post_pstn usg
WHERE
datatype_id in (808005,808045,808046,808050,808018,808019)
and Resultmessage_id is null and eventbegindate between '05/01/2007' and '05/05/2007' and
eventclass_id not in (500109,500110,500111,500112,500113,500114,500115, 500116,500120,500107,500108,500106,500086)
GROUP BY STREAM_ID,
STREAMROW,
EVENTBEGINDATE,
EVENTBEGINTIME,
EVENTTIME,
cast(replace(CALLINGNUMBER, '+', '') as char(20)),
Case
when gcalledprefix_id is not null and gconnectedprefix_id is not null and gcalledprefix_id != gconnectedprefix_id
then cast(replace(CONNECTEDNUMBER, '+', '') as char(20))
else cast(replace(CALLEDNUMBER, '+', '') as char(20))
End,
gcallingprefix_id,
Case
when gcalledprefix_id is not null and gconnectedprefix_id is not null and gcalledprefix_id != gconnectedprefix_id
then gconnectedprefix_id
when gcalledprefix_id is not null then gcalledprefix_id
else gconnectedprefix_id
End,
EVENTCLASS_ID,
TARIFFPLANVARIANT_ID,
substr(accountnumber,1,20),
TYTAN_ACT_TP,
GUIDINGCPARTY_ID,
GUIDINGCPACCOUNT_ID,
GUIDINGAPNAME_ID,
GUIDINGCITEM_ID