Link to home
Create AccountLog in
Microsoft SQL Server 2008

Microsoft SQL Server 2008

--

Questions

--

Followers

Top Experts

Avatar of rochestermn
rochestermn🇺🇸

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

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of rochestermnrochestermn🇺🇸

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

Avatar of rochestermnrochestermn🇺🇸

ASKER

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

Avatar of vdr1620vdr1620🇺🇸

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

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of rochestermnrochestermn🇺🇸

ASKER

Awesome response.  I will try to make this work thank you sir.

Avatar of rochestermnrochestermn🇺🇸

ASKER

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

Avatar of rochestermnrochestermn🇺🇸

ASKER

see attached capture
Capture.JPG

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of vdr1620vdr1620🇺🇸

change the expression  to DATEADD(D,SUBSTRING(gldate,4,3),(DT_DBDATE)(gldate))


i just changed @gldate to gldate

Avatar of rochestermnrochestermn🇺🇸

ASKER

See the new errors
Capture.JPG

Avatar of rochestermnrochestermn🇺🇸

ASKER

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.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of vdr1620vdr1620🇺🇸

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)

Avatar of vdr1620vdr1620🇺🇸

It should be jdate instead of gldate in Derive transformation 1

 DayofYear - (DT_I4)(SUBSTRING(jdate,4,3))

Avatar of rochestermnrochestermn🇺🇸

ASKER

Ok I will try this adjustment and report back.  Thank you.

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of rochestermnrochestermn🇺🇸

ASKER

How do you test these expressions anyway?  Is there some way in the IDE?

Avatar of vdr1620vdr1620🇺🇸

in a package using two derived column transformations as i suggested

Avatar of rochestermnrochestermn🇺🇸

ASKER

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.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of rochestermnrochestermn🇺🇸

ASKER

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


Avatar of vdr1620vdr1620🇺🇸

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

Avatar of vdr1620vdr1620🇺🇸

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

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of rochestermnrochestermn🇺🇸

ASKER

I dont see an option to do that.  Also if I click Debug/Start Debugging it is disabled.
ie.  pressing F5 doesnt do anything.

Avatar of vdr1620vdr1620🇺🇸

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 ?

Avatar of rochestermnrochestermn🇺🇸

ASKER

I do not know but i am editing in the visual studio 2008 business intelligence IDE.

See attached image.
Capture.JPG

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of vdr1620vdr1620🇺🇸

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

Avatar of rochestermnrochestermn🇺🇸

ASKER

Ok.  I will try that thanks i had no idea.  Will let you know when this is good to go.

Avatar of rochestermnrochestermn🇺🇸

ASKER

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

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of rochestermnrochestermn🇺🇸

ASKER

When I executed it ended but the data didnt go in the table I dont think.
Capture.JPG

Avatar of vdr1620vdr1620🇺🇸

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

Avatar of rochestermnrochestermn🇺🇸

ASKER

Ok these are the errors.  
Capture.JPG

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of vdr1620vdr1620🇺🇸

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

Avatar of rochestermnrochestermn🇺🇸

ASKER

Ok it ran but my dates are all in 1900s.


Capture.JPG

ASKER CERTIFIED SOLUTION
Avatar of vdr1620vdr1620🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of rochestermnrochestermn🇺🇸

ASKER

How do I change the dateformat to short date in this format:  10/3/2011?

Thanks again.

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of vdr1620vdr1620🇺🇸

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


Avatar of rochestermnrochestermn🇺🇸

ASKER

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!

Avatar of rochestermnrochestermn🇺🇸

ASKER

This guy went way above and beyond what is normal im very greatful for his help.  Awesome.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of vdr1620vdr1620🇺🇸

I'm glad I was able to help you

Avatar of rochestermnrochestermn🇺🇸

ASKER

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"
Microsoft SQL Server 2008

Microsoft SQL Server 2008

--

Questions

--

Followers

Top Experts

Microsoft SQL Server 2008 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. Major improvements include the Always On technologies and support for unstructured data types.