First off, I'm new to this forum and I would just like to send a big HI! to everyone.
Ok, so I am fairly new at this SQL/StoredProcedure stuff, I am an experienced C/C++ programmer (about 10years) but I was just thrown into this project and I have to come through.
Here is the situation, we have a PBX phone system, that puts out data onto an MS SQL server 7. There is a table with 3 (relevant) fields:
PhoneNumber (varchar(10)), CallStart (datetime) and CallEnd (datetime).
There are two queries that I need:
I needed one that tells me the number of calls that were made within any given day and that day only (meaning the call started and ended between 00:00:00AM and 23:59:59) this one I have written as:
set @DateFrom = '01/22/04 00:00:01'
set @DateTo = '01/22/04 23:59:59'
Select @Calls = count(*)
from PBXRecords
where CallStart > @DateFrom and CallEnd < @DateTo
Which seems to work fine...
The BIG problem is that I need a query to know the seconds that the PBX was used on a given date and not just add up the seconds of the calls that a query similar to the previous one would return. But true number od seconds used during the day.
The problem comes when a call starts before midnight and ends during the day in question (TDIQ). There are 4 cases:
Case 1 Calls that start and end within TDIQ. (simple case)
Case 2 Calls that start before TDIQ and end during TDIQ.
Case 3 Calls that start during TDQI and end after TDIQ.
Case 4 Calls that start before TDIQ and ends after TDIQ.
Diagram:
timeline -------------|--TODAY--|------------
case 1 ------------------[CALL]--------------
case 2 -------------[CALL]-------------------
case 3 -----------------------[CALL]---------
case 4 -----------[ VERY LONG CALL ]---------
(fixed width font helps visualize this diagram...)
I need to know the ONLY the total number of seconds of all the calls that happened ONLY WITHIN TDIQ.
And similarly I need a list of all the phone numbers dialed from the PBX during TDIQ, with a total number of seconds per phonenumber (not per call) of the number of seconds that each phone number was called. Again with all the calls that had any portion of it duringTDIQ.
I've been racking my brain against this problem and I can't come up with a solution and I don't think it should be "that" hard.
Any SQL geniuses out there that can give a hand?
Thanks in advance for any and all responses,
BarFly
Ok, so I am fairly new at this SQL/StoredProcedure stuff, I am an experienced C/C++ programmer (about 10years) but I was just thrown into this project and I have to come through.
Here is the situation, we have a PBX phone system, that puts out data onto an MS SQL server 7. There is a table with 3 (relevant) fields:
PhoneNumber (varchar(10)), CallStart (datetime) and CallEnd (datetime).
There are two queries that I need:
I needed one that tells me the number of calls that were made within any given day and that day only (meaning the call started and ended between 00:00:00AM and 23:59:59) this one I have written as:
set @DateFrom = '01/22/04 00:00:01'
set @DateTo = '01/22/04 23:59:59'
Select @Calls = count(*)
from PBXRecords
where CallStart > @DateFrom and CallEnd < @DateTo
Which seems to work fine...
The BIG problem is that I need a query to know the seconds that the PBX was used on a given date and not just add up the seconds of the calls that a query similar to the previous one would return. But true number od seconds used during the day.
The problem comes when a call starts before midnight and ends during the day in question (TDIQ). There are 4 cases:
Case 1 Calls that start and end within TDIQ. (simple case)
Case 2 Calls that start before TDIQ and end during TDIQ.
Case 3 Calls that start during TDQI and end after TDIQ.
Case 4 Calls that start before TDIQ and ends after TDIQ.
Diagram:
timeline -------------|--TODAY--|------------
case 1 ------------------[CALL]--------------
case 2 -------------[CALL]-------------------
case 3 -----------------------[CALL]---------
case 4 -----------[ VERY LONG CALL ]---------
(fixed width font helps visualize this diagram...)
I need to know the ONLY the total number of seconds of all the calls that happened ONLY WITHIN TDIQ.
And similarly I need a list of all the phone numbers dialed from the PBX during TDIQ, with a total number of seconds per phonenumber (not per call) of the number of seconds that each phone number was called. Again with all the calls that had any portion of it duringTDIQ.
I've been racking my brain against this problem and I can't come up with a solution and I don't think it should be "that" hard.
Any SQL geniuses out there that can give a hand?
Thanks in advance for any and all responses,
BarFly