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 2012 Forums
 Analysis Server and Reporting Services (2012)
 How to get previous month's number

Author  Topic 

sikni8
Starting Member

2 Posts

Posted - 2014-06-19 : 17:07:34
I have the following SSIS expression:

Right("0" + (DT_STR,4,1252) DatePart("m",getdate()),2) + RIGHT("0" + (DT_STR,4,1252) DatePart("yyyy",getdate()),2)

which gives me 0614.

How can I change the month code so it always gives me the previous month's number?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-06-19 : 17:13:32
Just subtract 1 from the datepart month calculation.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

sikni8
Starting Member

2 Posts

Posted - 2014-06-20 : 09:14:39
I did that and it didn't work :/
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-06-20 : 12:44:20
This doesn't work?: DatePart("m",getdate()),2)-1

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -