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
 SSIS and Import/Export (2008)
 4 years subtract from date

Author  Topic 

Sonu619
Posting Yak Master

202 Posts

Posted - 2011-01-26 : 23:18:08
Hi guys,

I am stuck middle of the project need help, requirement is i have date 1-1-1900 and i want to display 1-1-1900 - 4 years ( i want to subtract 4 years from 1-1-1900). I need expression in SSIS.I am using ssis to finish this project. Please let me know if my question is not clear or need more information. Thanks.

mrmkhokhar
Starting Member

7 Posts

Posted - 2011-01-27 : 05:11:30
pick day, year and month separately and then subtract 4 from year and concat month+day+year

Let me know if this works?

ETL/Database Developer
Go to Top of Page

chanluongbus
Starting Member

5 Posts

Posted - 2011-01-27 : 12:56:14
Go to the following blog. http://ssrsdeveloper.blogspot.com/p/sql101.html
Under working with Dates it might help you. Let me know if it help.


CL
Go to Top of Page

Sonu619
Posting Yak Master

202 Posts

Posted - 2011-01-27 : 20:32:57
Mrmkhokhar thanx for your reply, i have date field "1-1-1900" How i can Separate day/month/year in SSIS? Thanks for your help. I know i can use derived transformation but i don't know function?
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-01-27 : 21:41:26
Just use the DATEADD() function

DATEADD(year, -3, '1-1-1900')
Go to Top of Page

mrmkhokhar
Starting Member

7 Posts

Posted - 2011-01-31 : 01:27:40
Below is your solution along with the formating, just specify your date instead of getdate(). you can declare a variable for that


RIGHT("0000" + (DT_STR,50,1252)(((DT_I4)DATEPART("YYYY",GETDATE())) - 4),4) + "-" + RIGHT("00" + (DT_STR,50,1252)DATEPART("MM",GETDATE()),2) + "-" + RIGHT("00" + (DT_STR,50,1252)DATEPART("DD",GETDATE()),2)

ETL/Database Developer
Go to Top of Page

mrmkhokhar
Starting Member

7 Posts

Posted - 2011-01-31 : 01:36:09
you may also use DATEADD("YYYY",-4,@[User::dateVar]) if formating is not a concern.

ETL/Database Developer
Go to Top of Page
   

- Advertisement -