June 10, 2009 at 1:50 am
Is there a way in SQL 2005 (a function would be great but I doubt it) to calculate the relative month i.e. current month is zero, previous -1, etc, without having to write the code by long hand?
The issue becomes more complicated once you step over the 12 month threshold, otherwise it would just have been a difference between the dates such as
MONTH(GETDATE())-MONTH(date_value) AS relative_month
Thx for your help
June 10, 2009 at 1:57 am
SELECT DATEADD(month, -1, GETDATE())
DECLARE @NoPrevious INT
SET @NoPreviou = 13
SELECT DATEADD(month, -@NoPrevious, GETDATE())
June 10, 2009 at 2:00 am
select datediff(month,getdate(),'01jan2000')
June 10, 2009 at 3:36 am
hmmmm....
simple and effective....where is my brain this morning :blush:
Thx for the code..
June 10, 2009 at 2:23 pm
haha.. happens sometimes.. happened to me too...
Happy coding
-RP
June 10, 2009 at 11:30 pm
Combine brain failure and working with Oracle in place of SQL Server for the last few months... and bingo!
Forget all the functions and the most simple of methods.. 😛
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply