Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SQL Server query question

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-11-02 : 07:47:16
David writes "I am not quite sure how to approach this problem. I have data provided to me that is in my mind very hard to work with. The calls handled column is a monthly accumulative total. I want to be able to add a column to my query or table that will subtract the calls_handled total from the previous week.
An example would be:

I would like to add a new coulumn called "actual_calls". This would be a total that is calculated from calls_handled - the previous weeks called handled.

In this case 111 calls hadled would be the first weeks "actual_calls" number of calls. This would not have a previous week to subtract because it is the first week of the month.

The second weeks actual calls handled would be 514-111.

The third week actual calls handled would be 912-514 etc.

The data is provided to me on a weekly basis and there is always a final month end total sent to me on the last day of each month to account for all the data for a given month. Then the whole process starts over for the next month.

What is the best approach to calculate what the actual call numbers are for a given week?

SQL SERVER 2000
Windows 2003




date_id  person_id calls_handled

20060203	22008   	111
20060210 22008 514
20060217 22008 912
20060224 22008 1358
20060228 22008 1514
20060303 22008 476
20060310 22008 1211
20060317 22008 1858
20060324 22008 2402
20060331 22008 3047
20060407 22008 685
20060414 22008 1361
20060421 22008 1911
20060428 22008 2246
20060430 22008 2421
"

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-02 : 07:51:33
Then you will get a negative value for 20060303 and 20060407. Is that correct?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -