Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a Query

Status
Not open for further replies.

tkoehn

ISP
May 24, 2001
26
0
0
US
I have a table with call data having fields CustomerName, CalledStationID and TotalConnectTime.

I need to query all all records in the database for a specfied date Range which typically will be the 1st of each month to the end of each month.

Let me clarify that AnyStationID is any CalledStationID that is not SpecificStationID and SpecificStationID we will say is 888-555-1212.

The Query needs a responce that is grouped by CustomerName and will return 2 additional fields in the following format:

CustomerName, Sum(TotalConnectTime for AnyStationID), Sum(TotalConnectTime for SpecificStationID).

So, I need to know Total Connect Time for All Calls made to any number except 888-555-1212 and I need Total Connect Time for all calls made to 888-555-1212 in the 3rd field returned.

Anyone have any idea how I need to do this?

Thanks in advance.

Tony
 
Here is one T-SQL solution.

Select
CustomerName,
Sum(Case When CalledStationID<>'888-555-1212'
Then TotalConnectTime
Else 0 End) As TotalAnyID,
Sum(Case When CalledStationID='888-555-1212'
Then TotalConnectTime
Else 0 End) As TotalSpecificID
From TblName
Group By CustomerName
Order By CustomerName
Terry L. Broadbent
Programming and Computing Resources
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top