?
Solved

Change format of a date value in an SSIS variable to a text string of the format 'yyyymmdd'

Posted on 2007-04-08
6
Medium Priority
?
802 Views
Last Modified: 2013-12-08
I use a variable in a SQL Integration Services Package, DATEADD( "day",-365, GETDATE())  that returns a date as follows:08 Apr 2006 08:56. I want to change the value of the variable to: '20060406' as I need to use it in a SAP SQL statement. How can I do that?
0
Comment
Question by:cErasmus
  • 3
  • 3
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18873237
CONVERT(varchar(8), DATEADD( year,-1, GETDATE()) , 112 )  
0
 
LVL 1

Author Comment

by:cErasmus
ID: 18874846
Thanks for your response, however I get the following error message: "The function "varchar" was not recognized. Either the function name is incorrect or does not exist.

Attempt to parse the expression "CONVERT(varchar(8), DATEADD( "year",-1, GETDATE()) , 112 )" failed and returned error code 0xC004708A. The expression cannot be parsed. It might contain invalid elements or it might not be well-formed. There may also be an out-of-memory error.

 (Microsoft.DataTransformationServices.Controls)"

Also note that I'm using the SSIS Expression Builder to create this variable. Further help will be appreciated.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18874851
I see. for SSIS, the following should work:
REPLACE( (DT_DBDATE)DATEADD( "year",-1, GETDATE()), "-", "")

http://msdn2.microsoft.com/en-us/library/ms141704.aspx
http://msdn2.microsoft.com/en-us/library/ms141196.aspx
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 1

Author Comment

by:cErasmus
ID: 18874946
My initial try with your proposed solution gave the following error: "The function "REPLACE" does not support the data type "DT_DBDATE" for parameter number 1. The type of the parameter could not be implicitly cast into a compatible type for the function. To perform this operation, the operand needs to be explicitly cast with a cast operator.

Evaluating function "REPLACE" failed with error code 0xC0047089."

All I want to do is to change the result of DATEADD( "day",-365, GETDATE()) which is 9 Apr 2006 08:56.  to: '20060409'.

I have tried the following:  (DT_WSTR, 30) YEAR(DATEADD( "year", -1, GetDate()))+(DT_WSTR, 30) MONTH(DATEADD( "year", -1, GetDate()))+(DT_WSTR, 30) DAY(DATEADD( "year", -1, GetDate()))
with the result: 200649. As you can see the zeros are missing.
 
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 18875822
I see. let us try this:
REPLACE( (DT_WSTR, 30)(DT_DBDATE)DATEADD( "year",-1, GETDATE()), "-", "")

Note: I cannot try mysql, i don't have SSIS installed here at home...
0
 
LVL 1

Author Comment

by:cErasmus
ID: 18878350
Thanks angellll, I apprecialte your rapid and good responses
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question