Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

expression yyyymm with mm-1 Expand / Collapse
Author
Message
Posted Monday, July 28, 2014 6:56 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, September 19, 2014 12:27 AM
Points: 62, Visits: 328
In My derived column I want expression for getting yyyymm ( where mm is mm-1)

Expression in Derived Column

(DT_STR,4,1252)DATEPART("yyyy",GETDATE()) + RIGHT("0" + (DT_STR,2,1252)DATEPART("mm",GETDATE()),2)

Result : 201407

Expected Result : 201406
Post #1596821
Posted Monday, July 28, 2014 7:11 AM This worked for the OP Answer marked as solution


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 7:23 PM
Points: 20,860, Visits: 32,883
Shanmuga Raj (7/28/2014)
In My derived column I want expression for getting yyyymm ( where mm is mm-1)

Expression in Derived Column

(DT_STR,4,1252)DATEPART("yyyy",GETDATE()) + RIGHT("0" + (DT_STR,2,1252)DATEPART("mm",GETDATE()),2)

Result : 201407

Expected Result : 201406


Try this:

(DT_STR,4,1252)DATEPART("yyyy",DATEADD("Month",-1,GETDATE())) + RIGHT("0" + (DT_STR,2,1252)DATEPART("mm",DATEADD("Month",-1,GETDATE())),2)




Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1596841
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse