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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hourly Breakdown

Status
Not open for further replies.

timferris

IS-IT--Management
Feb 20, 2001
12
0
0
GB
Hi there,

I'm trying to write some SQL that will run through a table I have, adding up the values in one column, for each hour they were logged.

For example, 8-9am 3 calls logged
9-10am 6 calls logged

 
Hi timferris,
I don't know the exact usage, but may be this is what you are looking for.
Suppose your table is having this structure:
CREATE TABLE myTable (TimeHour INT, No_Of_Calls INT)
Then create this procedure
CREATE PROCEDURE updCallLog AS
DECLARE @pTimeHour INT
SELECT @pTimeHour=CONVERT(INT,CONVERT(char(2),getdate(),108))
IF EXISTS (SELECT * FROM myTable WHERE TimeHour=@pTimeHour)
UPDATE myTable
SET No_Of_Calls = No_Of_Calls + 1
WHERE TimeHour=@pTimeHour
ELSE
INSERT myTable VALUES (@pTimeHour, 1)


Now whenever you want to update your table , just issue the command UpdCallLog


You may have to make changes in the procedure depending on your actual requirement. If further you face any problem, just keep posted.
 

Use a simple query to return the results you want.

Select
datepart(hh,LogTime) As LogHour,
sum(CallCount) As TotCount
From table
Group By datepart(hh,LogTime)

You could insert the result into another table, display, or process it however you need. Terry L. Broadbent
faq183-874 contains some tips and ideas for posting questions in these forums. Please review it and comment if you have time.
NOTE: Reference to the FAQ is part of my signature and is not directed at any individual.
 
Hey thanks for that, Terry yours is the one that I am going to go with. Thanks also rajeevnandanmishra

Regards

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top