• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1655
  • Last Modified:

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
0
rochestermn
Asked:
rochestermn
  • 22
  • 14
1 Solution
 
rochestermnAuthor Commented:
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
0
 
rochestermnAuthor Commented:
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
0
 
vdr1620Commented:
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
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
rochestermnAuthor Commented:
Awesome response.  I will try to make this work thank you sir.
0
 
rochestermnAuthor Commented:
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
0
 
rochestermnAuthor Commented:
0
 
vdr1620Commented:
change the expression  to DATEADD(D,SUBSTRING(gldate,4,3),(DT_DBDATE)(gldate))


i just changed @gldate to gldate
0
 
rochestermnAuthor Commented:
See the new errors
Capture.JPG
0
 
rochestermnAuthor Commented:
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.
0
 
vdr1620Commented:
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)
0
 
vdr1620Commented:
It should be jdate instead of gldate in Derive transformation 1

 DayofYear - (DT_I4)(SUBSTRING(jdate,4,3))
0
 
rochestermnAuthor Commented:
Ok I will try this adjustment and report back.  Thank you.
0
 
rochestermnAuthor Commented:
How do you test these expressions anyway?  Is there some way in the IDE?
0
 
vdr1620Commented:
in a package using two derived column transformations as i suggested
0
 
rochestermnAuthor Commented:
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.
0
 
rochestermnAuthor Commented:
Ive gotten rid of all errors.  I just need to know how to run it or preview it to see the results.

0
 
vdr1620Commented:
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
0
 
vdr1620Commented:
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
0
 
rochestermnAuthor Commented:
I dont see an option to do that.  Also if I click Debug/Start Debugging it is disabled.
ie.  pressing F5 doesnt do anything.
0
 
vdr1620Commented:
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 ?
0
 
rochestermnAuthor Commented:
I do not know but i am editing in the visual studio 2008 business intelligence IDE.

See attached image.
Capture.JPG
0
 
vdr1620Commented:
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
0
 
rochestermnAuthor Commented:
Ok.  I will try that thanks i had no idea.  Will let you know when this is good to go.
0
 
rochestermnAuthor Commented:
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
0
 
rochestermnAuthor Commented:
When I executed it ended but the data didnt go in the table I dont think.
Capture.JPG
0
 
vdr1620Commented:
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
0
 
rochestermnAuthor Commented:
Ok these are the errors.  
Capture.JPG
0
 
vdr1620Commented:
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
0
 
rochestermnAuthor Commented:
Ok it ran but my dates are all in 1900s.


Capture.JPG
0
 
vdr1620Commented:
That is bcz of the Expression here - (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"


This is a If else condition it is checking for 1st character and If its 2 then it returns 20 or else 19 ... change it to "1" ? "20":"19" or as you like
0
 
rochestermnAuthor Commented:
How do I change the dateformat to short date in this format:  10/3/2011?

Thanks again.
0
 
vdr1620Commented:
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

0
 
rochestermnAuthor Commented:
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!
0
 
rochestermnAuthor Commented:
This guy went way above and beyond what is normal im very greatful for his help.  Awesome.
0
 
vdr1620Commented:
I'm glad I was able to help you
0
 
rochestermnAuthor Commented:
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"
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 22
  • 14
Tackle projects and never again get stuck behind a technical roadblock.
Join Now