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 2008 Forums
 Analysis Server and Reporting Services (2008)
 Problem subtracting 1 from year

Author  Topic 

bh0526
Yak Posting Veteran

71 Posts

Posted - 2011-09-06 : 14:30:17
I simply want to subtract 1 from today's year and display only the year like "2010". I have tried a million different DATEADD methods and nothing I do works. Can anyone help?

Thanks,

Bob

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-09-06 : 14:34:05
SELECT DATEPART(year, GETDATE())-1

That works in T-SQL, not sure about Analysis Services but should be similar.
Go to Top of Page

bh0526
Yak Posting Veteran

71 Posts

Posted - 2011-09-06 : 14:50:24
I am using SSRS not T-SQL. Your solution does not work. I get this error:

'Year' is invalid. ArgumentsWrong
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-09-06 : 14:58:49
Then use this in an expression:

=Year(Now())-1
Go to Top of Page

bh0526
Yak Posting Veteran

71 Posts

Posted - 2011-09-06 : 15:28:23
That worked Rob. Thanks!
Go to Top of Page
   

- Advertisement -