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 |
jay83091
Starting Member
14 Posts |
Posted - 2010-07-01 : 01:12:16
|
Hi Experts,I have a detailed date dim table trying to figure out a way to create a column that indicates 'Calendar Type' (i.e. determines whether the period [e.g. 200912, 201001 etc] is the current QTD or previous QTD)e.g. for the current month of July 201020104 - previous QTD20105 - previous QTD20106 - previous QTD20107 - current QTD20108 - current QTD20109 - current QTDthanks for your help in advanceI have these in the view already.Current MAT 201001Current YTD 201001Month 201001Current MAT 201002Current YTD 201002Month 201002Previous Month 201002Current MAT 201003Current Month 201003Current YTD 201003Month 201003Month 201004Month 201005Month 201006Month 201007Month 201008Month 201009Month 201010Month 201011Month 201012 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-07-01 : 01:53:09
|
[code]select datecol, case when datecol >= dateadd(quarter, datediff(quarter, 0, getdate()), 0) then 'Current' else 'Previous' endfrom yourtable[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
jay83091
Starting Member
14 Posts |
Posted - 2010-07-01 : 02:29:17
|
thanks for the reply.woudln't this code apply 'Current' to all period beyond?i.e. when we are on July 2010,Current QTD will be displayed on 'Calendar Type' based on period 201007,201008,201009Previous QTD will be displayed on 'Calendar Type' based on previous period of 201004, 201005, 201006and from period 201010 onwards, it wouldn't apply yet.Looking to things like this below.Period / Calendar Type201004 / Previous QTD201005 / Previous QTD201006 / Previous QTD201007 / Current QTD201008 / Current QTD201009 / Current QTD201010 / NULLand once the calendar hits 2010 Oct, it would change to Current QTD |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-07-01 : 07:59:35
|
[code]select datecol, case when datecol > dateadd(quarter, datediff(quarter, 0, getdate()) + 4, 0) then 'Future' when datecol >= dateadd(quarter, datediff(quarter, 0, getdate()), 0) and datecol < dateadd(quarter, datediff(quarter, 0, getdate()) + 4, 0) then 'Current' else 'Previous' endfrom yourtable[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
jay83091
Starting Member
14 Posts |
Posted - 2010-07-01 : 22:51:11
|
Thanks Mateyou are the best |
 |
|
|
|
|
|
|