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 2005 Forums
 Transact-SQL (2005)
 rolling 13 months in query

Author  Topic 

michaelb
Yak Posting Veteran

69 Posts

Posted - 2008-06-23 : 02:19:43
Hi,

I'm writing a query that will be calculating a number of business performance measures including the following...

Average Stock:
This is calculated by taking the actual stock value of the product category per month and dividing it by 13 if we have over 12 month's history, or if a new product, then by the number of months we have had it in stock for.

Cost of Goods Sold Annualised:
This is an average figure for the year of the sold landed costs for the product category over a 13 month period if we have over 12 months history. If it's a new product, then it's for the number of months we have had stock.

My question is, how do I tell the query to go back 13 months from the current month?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-23 : 02:31:50
http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx

SELECT DATEADD(MONTH, -13, GETDATE())



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -