Link to home
Start Free TrialLog in
Avatar of rochestermn
rochestermnFlag for United States of America

asked on

Convert JDE Julian Date in SSIS

I have a JDE julian date that I need to convert to short date in a derived colums data flow task.

An example value of the date in the sql database is 111222. (08/10/2011)

The JDE julian date is 6 digits.  I can create a function in sql server to do this but the
dba doesnt want any functions in that particular db.

So I need to figure out how to do this in the IDE for SSIS.  Im not sure if there is a place to write
a custom function in the IDE or if I have to use the built in functions to try and convert.

See attached screen.
Capture.JPG
Avatar of rochestermn
rochestermn
Flag of United States of America image

ASKER

Seems to me I need to use a script component in SSIS to handle the transformation of the julian date.

All the other fields should go straight in with little transform.  

Ive never used the script component before so im trying figure it out.   Im assuming you have to use either the script component or derive columns not both in the same data flow.


Capture.JPG
Im not allowed to use the script component.

So somehow i have to figure out how to convert a julian date back to a regular date.

The julian date is lets say 111222.

All that I have available to me in SSIS is dateadd, datediff, datepart, day, getdate, month and year functions.  Most of which require a date field as a parameter.

If anyone has any ideas I appreciate.  I am using two derived tasks to split the julian date
into  century = 1, year = 11, and day =222.

Thanks
you can do this in two steps, meaning two derived columns thought it can be achieved using 1 derived column... the problem is it errors out while converting the string to date when try to do it using only one derived column ..so will have to use 2

1st Derived Column (OutputColumn as gldate, inputcolumn as Jdate)

(DT_STR,20,1252)(SUBSTRING((DT_STR,10,1252)Jdate,1,1) == "2" ? "20" : "19") + SUBSTRING((DT_STR,10,1252)Jdate,2,2) + "-01-01"

2nd Derived Column

DATEADD(D,SUBSTRING(@gldate,4,3),(DT_DBDATE)(gldate))

Let me know, if you have any issues..

p.s.i have used a case to check for century and the code is based on the sql here
 http://www.dbforums.com/microsoft-sql-server/1646454-sql-day-year-cyyddd-datetime-mm-dd-yyyy-conversion.html
Awesome response.  I will try to make this work thank you sir.
Here are the errors from derived #2.  Also to note the day parm in dateadd is "day"

See attached image.  derived #1 was free of error.

thanks again.
Capture.JPG
change the expression  to DATEADD(D,SUBSTRING(gldate,4,3),(DT_DBDATE)(gldate))


i just changed @gldate to gldate
See the new errors
Capture.JPG
Looks like the 2nd part of the formula needs to be a numeric type.

so if you use substring it has to be cast I think.
My bad ..should have tested it before posting it..the below solution works

In Derived transformation 1 .. Add another column to derive the DayofYear - (DT_I4)(SUBSTRING(gldate,4,3)) and use this column in the Derived Transformation 2

DATEADD("D",DayOfYear,(DT_DBDATE)gldate)
It should be jdate instead of gldate in Derive transformation 1

 DayofYear - (DT_I4)(SUBSTRING(jdate,4,3))
Ok I will try this adjustment and report back.  Thank you.
How do you test these expressions anyway?  Is there some way in the IDE?
in a package using two derived column transformations as i suggested
I mean how do you test the results or your function?  Im totally new to SSIS.  As a programer im used to having a way to test my code but dont see a way in SSIS.  For example you can type in function syntax  but how do you know its going to work if you cant execute it?

Ive almost got it but there are a few errors about converting unicode to string.
Error      1      Validation error. Data Flow Task OLE DB Destination [454]: Column "col1" cannot convert between unicode and non-unicode string data types.        JDE_Export_EBMS.dtsx      0      0      

Thanks.
Ive gotten rid of all errors.  I just need to know how to run it or preview it to see the results.

convert the column in one of the derived transformation tasks by using (DT_STR,Length,1252) (col1)  ,name it accordingly in the column provided and map this to your destination.. Now, to look at the output all you need to do is rt click on the precedence container (arrow joining two tasks) and then select data viewers and Add a data viewer .

You can add it b/w the derived column and the destination to see all your columns before loading them into the table ..

Also, change the column data type according to your destination column.. if its NVarchar convert it using (DT_WSTR,Length)(col1), if varchar use the above exp

http://sqlblog.com/blogs/andy_leonard/archive/2010/03/08/ssis-snack-grid-data-viewer.aspx
if you want to run the complete package ..Rt click on the package and select execute..

If you wan to run a Task (data flow task etc)..rt click on it and select Execute
I dont see an option to do that.  Also if I click Debug/Start Debugging it is disabled.
ie.  pressing F5 doesnt do anything.
Is the task disabled ? if its sql 2008 you can rt click on the empty space in the data flow task and run the task.. do you see the solution File and package in solution explorer window ?
I do not know but i am editing in the visual studio 2008 business intelligence IDE.

See attached image.
Capture.JPG
hmm.. i see that you are missing the Project itself and is open in the design mode..which only allos you to edit the package, save the changes and if you want o run..you will need to run it by double clicking the .dtsx file from physical location..it would just run and states about the output..

you can actually follow the below link and run it from Visual studio
http://blogs.msdn.com/b/michen/archive/2007/03/15/ssis-debug-disabled.aspx
Ok.  I will try that thanks i had no idea.  Will let you know when this is good to go.
Ok this explains the missing project.

I had saved the .dtsx file out on the network and was editing it directly instead of opening the solution file.  See attached screen.
Capture.JPG
When I executed it ended but the data didnt go in the table I dont think.
Capture.JPG
of course it did not because there were validation errors at the destination..  click on Progress tab beside Package explorer and look for error messages
Ok these are the errors.  
Capture.JPG
open your OLE DB destination and review your mappings..as the error describes column meta data is Invalid.. check the data types of your source and destination Columns in the Columns tab of your destination task ...they nned to be same, if you change them .. rempa them again
Ok it ran but my dates are all in 1900s.


Capture.JPG
ASKER CERTIFIED SOLUTION
Avatar of vdr1620
vdr1620
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How do I change the dateformat to short date in this format:  10/3/2011?

Thanks again.
It is in a short date Format .. you cannot really mention the format of the date Type Field, I mean SQL treats all the dates as in one single date format .. my sentence might really not make sense but what I mean can be illustrated by an example below...Run this script in your SQL browser Window and see the output results for yourself..

you can the run the package as is ..and sql wll make the changes... Now, if the data type is not Date then we will need to change that in the Derived Transformation by replacing "-" with "/" and interchange the date format to DD/MM/YYYY
CREATE TABLE #D
(
D Date
)

INSERT INTO #D VALUES ('2011-03-03')
INSERT INTO #D VALUES ('02/02/2011')

SELECT * FROM #D

DROP TABLE #D

Open in new window

Point well taken.  Its fine.  Thanks for all your help you have done an amazing job for me and gone the extra mile and a half when most people typically dont.

Thank you very much sir!
This guy went way above and beyond what is normal im very greatful for his help.  Awesome.
I'm glad I was able to help you
Im having difficulty getting this date in the format mm-dd-yyyy.  The fomula below puts it in yyyy-mm-dd

Can someone help?


(DT_STR,20,1252)(SUBSTRING((DT_STR,10,1252)Jdate,1,1) == "1" ? "20" : "19") + SUBSTRING((DT_STR,10,1252)Jdate,2,2) + "-01-01"