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.
| Author |
Topic |
|
jung1975
Aged Yak Warrior
503 Posts |
Posted - 2003-08-25 : 11:52:19
|
Good morning! all, Here is the current Stored procedure that generate the total claim count and total loss amount by asofdate. Create procedure totalchange(@asofdate datetime)asselect convert(varchar(10),@asofdate, 101) as asofdate,sum(a.clmcount) as totclaimcount, sum(a.totloss)as totincurredfrom(select count(claim_key) as clmcount,clm_nbr,claim_key,clm_status,sum(loss_amt) as totloss from loss,claim,location_xrefwhere claim.ref_location = location_xref.location_key andclaim.claim_key = loss.loss_claim andloss.loss_date <= @asofdate andloss_type = 'R' andlocation_xref.ref_loc2 = 1069 andclm_incdate between '20010221' and '20010731 11:59:59'group by clm_nbr,claim_key,clm_status--, loss_amt,claim_key, clm_status) as aI would like to see the same result by month from asofdate 07/31/01 through 07/31/03 at one time ( I would like to see how does the value have changed for 25 months).The output should look like:Asofdate Total_claim Total_lossamount07/01/01 2234 13000000.0008/01/01 2400 13456789.0009/01/01 2480 14098756.98:::01/01/02 2800 19887273.75::07/01/03 4700 34566778.77 What would be the most efficent solution?Any comments or suggestions would be appreciated..ThanksJung |
|
|
simondeutsch
Aged Yak Warrior
547 Posts |
Posted - 2003-08-25 : 12:07:41
|
| Read Jeff Smith's article on Detecting Runs/Streaks In Your Data, it's still on the SQLTeam home page after Using Metadata. You need a variation of it- calculating a running summary. Or check out this article http://www.sqlteam.com/item.asp?ItemID=3856, an article by Garth on calculating running totals.Sarah Berger MCSD |
 |
|
|
|
|
|
|
|