Date Conversion problem - ssis

I was about to import data from a table in MySQL to SQL SErver 2008 through SSIS. But I cant transfer due to Dates in the table. There are some data of datetime data type, like '0001-01-10' which doesnt support in SQL Server where years in date ranges from 1753 to 9999. So how do i solve this in MySQL queries ?

If those dates are valid data, then there's no easy way to deal with that in SqlServer. Basically, a custom date handler is needed. A good-enough approximation might be achieved by separating the year into a single integer field and putting the month and day into a date field with a constant year. Every comparison would then be compound.
More likely—for most business applications—such dates are useless and should be cleaned up, or replaced by NULL values.

Note that none of the SSIS data types are truly equivalent to the SQL Server datetime or smalldatetime types, with their restricted range of allowable dates.
A lot of online documentation suggests the DT_DBTIMESTAMP is equivalent to SQL datetime. This is only true up to a point. Dates outside the allowed datetime range will happily cast to DT_DBTIMESTAMP (or any SSIS date type) - but will then cause an error if you try to write them out to an SQL datetime column.
Confusingly, SSIS represents external SQL datetime columns as DT_DBTIMESTAMP, suggesting that datetime and DT_DBTIMESTAMP are equivalent, when they're not.
This means that you can't anticipate out-of-range date problems in SSIS by casting. If you're eventually going to write to datetime or smalldatetime columns, you have to do an explicit check that the date is not out of range (<1/1/1753, or 1/1/1900 for smalldatetime).

Related

Migration of Data from Oracle database to SQL Server

[ADO NET Destination [2]] Error: An exception has occurred during data insertion, the message returned from the provider is: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
I don't understand the error message from SSIS. Please I need help.
Thanks
In C#, when the data is converted from NULL to DateTime, the DataTime.MinValue = 0001-01-01, but in database, the min value is 1/1/1753, so you have to make some treatments to NULL, otherwise when inserting 0001-01-01 (converted from NULL), it will throw you that error.
It is probably problem with different date formats on both sides, maybe different language setting for both databases. For example Oracle uses dd-MM-yyyy and SQL expects MM-dd-yyyy. Try to select datetime fields from both databases to check the format. Then try to solve it by some type of conversion in SSIS. You can try converting Oracle date to universal datetime format and then converting back to MS SQL date format. Of course, SSIS should solve it automatically, but working with dates is often buggy and confusing.
The other possibility is, that you are trying to convert TEXT column in Oracle to datetime column in MSSQL and one of the values in the table does not fit expected date format.

informatica Datetime conversion to SQL server Timstamp

I have a requirement where I have to load Informatica SESSSTARTTIME(datetime) to SQL server timestamp. When I am trying to connect datetime to timestamp I am getting error incompatible data type. 
Any suggestions how this can be achieved? 
Thanks
I had a similar issue in the past, where the date column was not getting loaded because of the difference in precision of date/time used by Informatica and SQL server. You can try this workaround: Change the data type in the target definition (not in SQL Server table, only in Informatica Target definition) to String, then Informatica will pass the date/time value in quotes when firing the insert query, which SQL server can convert to date/time automatically.
in the mapping try to create output port in expression as sessionstarttime (which is a inbuilt variable) and pass it to target
hope this will help to get desire output
in session there is config tab where you can change the format for date and time
MS SQL Server timestamp datatype has nothing to do with time. It's an autogenerated number and you cannot load it.
https://msdn.microsoft.com/en-us/library/ms182776(v=SQL.90).aspx
quote:
"Is a data type that exposes automatically generated, unique binary numbers within a database. timestamp is generally used as a mechanism for version-stamping table rows. The storage size is 8 bytes. The timestamp data type is just an incrementing number and does not preserve a date or a time. To record a date or time, use a datetime data type."

Converting Oracle timestamp(6) to datetime

I am pulling data in from an Oracle source (SSIS). After a week of successful run, a timestamp of '6/19/0002 12:00:00 AM' shows up. How do I convert this to SQL server datetime? I am fine with just setting this as null, but how do I detect invalid dates in ssis?
SQL Server 2008/SSIS 2012
I do not have control of Oralce source.
Thanks
I think you are probably looking for datetime2(6) in SQL Server 2008.
Defines a date that is combined with a time of day that is based on
24-hour clock. datetime2 can be considered as an extension of the
existing datetime type that has a larger date range, a larger default
fractional precision, and optional user-specified precision.

Dealing with Timestamp/Datetime when copying data from Oracle to SQL Server using SSIS

I am using SSIS to copy data from a table in Oracle to a table in SQL Server 2005. There's no transformation required, so it's just a straight line connecting OLE DB Source to OLE DB Destination. Fairly simple and works, but during execution, a record in the Oracle table contains a timestamp value of the year 0002 in encountered, so SSIS errors out due to an oveflow exception.
If I create an extra column in SQL Server with the data type of string, and remap, then that works fine. However, I prefer to keep the Datatime column and use it in my destination. I am OK with replacing the year 0002 with something like 1900 or something like that. So what's the best way to achieve this if-then-else in SSIS?
I usually let Oracle deal with that by using something like this in my source query:
CAST( Coalesce (
CASE
WHEN TO_CHAR(Effective_Date,'yyyy-mm-dd HH24:MI:SS') < '1900-01-01 00:00:00'
THEN TO_DATE('9999-12-31 00:00:00','yyyy-mm-dd HH24:MI:SS')
ELSE Effective_Date
END ,TO_DATE('9999-12-31 00:00:00','yyyy-mm-dd HH24:MI:SS')) AS DATE) AS Effective_Date
This sets a valid but very future date (dictated by the company I am on contract to as the representation of an invalid date in a required date field. You could also use '1900-01-01 00:00:00' instead of '9999-12-31 00:00:00') in cases where the original date is null or less than 1900-01-01 00:00:00. It also avoids post processing by SSIS on the date field.
I realize you have the fix you wanted, but the other method for dealing with issues of this sort is to use a conditional split. You can find and handle all sorts of data issues where you want to remove records from the main flow and do specific handling of them using conditional split. I find it especially handy when I want to be able to tell the vendor about the bad records they sent us so they can fix their data.

No datetime values populated from MySQL using SubSonic 3 Linq

I have a MySQL table with a couple of Datetime columns. The columns are set to allow null and some have default value '0000-00-00 00:00:00'. This is a conversion project from ASP to ASP.NET so the table is full of data, and where some rows still have the default value, so I had to set "Allow Zero Datetime=True" in the connectionstring to avoid the exception "Unable to convert MySQL date/time value to System.DateTime"
Now when I generate the code it all works fine and I get properties of type DateTime? for those columns, but when I query the database and populate an object representing the table all DateTime properties are null. Other properties gets populated their correct values.
Anybody knows why?
I'm using MySQL Connector 6.1.3 and SubSonic.Core compiled from the github today (11/17/2009)
I did some data cleaning. Updated all datetime columns to null where date was '0000-00...' and removed "Allow Zero Datetime=True" from the connectionstring, and then it works. Guess zero dates are not supported by SubSonic, and why should it, I don´t see any use for zero dates over null.
My trick for converting datetime format from different SQL DBMS is to load the column as VARCHAR. Then use string functions such as SUBSTRING and CONCAT to play around and get the desire format. From experience this saves a lot of time. No need to worry about dbms automatic conversion for datetime.
MySQL uses 'YYYY-MM-DD HH:MM:SS'