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 |
|
NickC
Yak Posting Veteran
68 Posts |
Posted - 2011-11-29 : 11:00:50
|
| HelloI am writing a query in which I run the following line -DENSE_RANK () OVER(Partition By rh.AccountingYear ORDER BY d.Quarterkey ASC) ENDThis ranks by Accounting year, and provides a ranking for each quarter, this produces the following results:2009 1 Q4 20092009 2 Q1 20102009 3 Q2 20102009 4 Q3 20102009 5 Q4 20102009 6 Q1 20112009 7 Q2 20112009 8 Q3 20112009 9 Q4 20112010 1 Q1 20102010 2 Q2 20102010 3 Q3 20102010 4 Q4 20102010 5 Q1 20112010 6 Q2 20112010 7 Q3 20112010 8 Q4 20112011 1 Q1 20112011 2 Q2 20112011 3 Q3 20112011 4 Q4 2011Now thats fine, for 2010, and 2011 however in 2009 we didn't start writing policies until the fourth quarter, so I need it to start from 4 for that quarter as its quarter 4 in 2009.so the results should look like this2009 4 Q4 20092009 5 Q1 20102009 6 Q2 20102009 7 Q3 20102009 8 Q4 20102009 9 Q1 20112009 10 Q2 20112009 11 Q3 20112009 12 Q4 20112010 1 Q1 20102010 2 Q2 20102010 3 Q3 20102010 4 Q4 20102010 5 Q1 20112010 6 Q2 20112010 7 Q3 20112010 8 Q4 20112011 1 Q1 20112011 2 Q2 20112011 3 Q3 20112011 4 Q4 2011Simples, except it can't be hard coded as different risks started being writen at different times - so not so simple for me :(Hoping its just a one line change or something , I did attempt a case statement after creating a left join to show min quarter however it failed miserably :( |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-29 : 11:33:41
|
| [code]SELECT Dr+(MAX(CASE WHEN DR=1 THEN REPLACE(QuarterKey,'Q','')*1 ELSE NULL END) OVER (PARTITION BY AccountingYear)-1) AS YourRankValue,...FROM(SELECTDENSE_RANK () OVER(Partition By rh.AccountingYear ORDER BY d.Quarterkey ASC) AS Dr,....FROM......)t[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-11-29 : 11:35:48
|
| If it's not too late, I find triangle reports much easier to do if you just calculate how many calendar year periods away from the original accident year period you are, and then let the front end figure out what the headings should be. I do my triangles AYQxCYQ, and this way the front-end can turn it into AYYxCYY or AYYxCYQ or whatever.JimEveryday I learn something that somebody else already knew |
 |
|
|
NickC
Yak Posting Veteran
68 Posts |
Posted - 2011-11-29 : 11:44:39
|
| Hi JimThis is first time I've ever done triangles, any guidence would be appreciated. |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-11-29 : 12:13:12
|
| Hopefully your underlying data has actual dates in it, an AccidentDate(when it happened) and an AccountingDate(the changes in value of the claim). You build out your triangles using a start date and an AsOf date. Your accident years quarters are determined by DATEDIFF(y,startdate,accidentdate) and your development periods are built using DATEDIFF(q,accidentdate,accountingdate). So your table will look something likeClaimNumber AccidentDate AccountingDate AYY CYQ 1 12/31/1999 12/31/1999 0 0 1 12/31/1999 03/31/2000 0 1... 1 12/31/1999 10/31/2011 0 48This should give you a good start. Once you get this you can worry about cumulating losses.JimEveryday I learn something that somebody else already knew |
 |
|
|
|
|
|
|
|