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 |
|
lingtrin
Starting Member
13 Posts |
Posted - 2007-06-20 : 13:17:39
|
| Hi, this is my first post here, i'm working on a view wich I have to display the results by period.1st period - Current month2nd period - Last month3rd period - Month before lastand so on.How can I achieve this? of course I have a column wich has the date I want to use, I was thinking on semthing like:case when DATEDIFF(M, TRXDATE, getdate()) <= 0 then ammount END as Period1(TRXDATE and ammount are columns on my table)Any ideas? would this work?Thanks for your replies |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-20 : 19:21:03
|
[code]CASE WHEN TRXDATE >= DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0) THEN ammount END AS Period1,CASE WHEN TRXDATE >= DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 1, 0) AND TRXDATE < DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0) THEN ammount END AS Period2,[/code] KH |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-21 : 10:29:28
|
| Also in the article's section read about Cross tab reportsMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|