I recently migrated a database from SQL Server 2008 to 2016. One of the side effects is that a raw output of a datetime field now contains milliseconds whereas before it didn't. Is there a way I can globally change this behaviour so a simple select * would output it without milliseconds.
Yes. Create a view that casts the data to a datetime2 datatype without the milliseconds. Then use that view for your joins if you so desire.
Or you can change the datatype of that column to a datetime2 type that does not have the millisecond precision and rebuild the table.
Related
We are migrating SQL Server system into Oracle implementation.
The application design date type:
SQL Server is achieved with DATETIME datatype EMPLOYEE(EMPLOYEE_HIRED DATETIME). Some of the columns contains time component as well till seconds.
Oracle is achieved with DATE datatype EMPLOYEE(EMPLOYEE_HIRED DATE). As we know, oracle date can hold time component as well
While migrating data from SQL Server to Oracle using SSIS, The system is defaulting it to TIMESTAMP datatype of oracle. Can this be defaulted to DATE?
There are around 1000+ such columns.
Do we need to address them manually through data conversion tool box? Can this be automated?
I found a difference in behaviour of adding date and datetime types in SQL Server 2012 and SQL Server 2016.
For the query:
select convert(date,getdate())+getdate()
I get error in SQL2016:
The data types date and datetime are incompatible in the add operator.
In 2012 it returns no error, just corect sum of dates.
What is the reason of such behaviour?
In SQL Server 2012, the operators were (silently?) changed to disallow mismatched types being added or subtracted. It apparently relates to the SQL Server 2008 ability to store Date and Time separately. You will need to cast to a common type (e.g. cast to date then to datetime).
Seems like a pretty large breaking change to me, but apparently Microsoft felt is was needed.
I have the requirement for dates that predate 1753, the minimum for datetime on SQL Server. DB-side, the solution is clear: change to datetime2 format. But it seems Informatica still treats the column as datetime. I suppose datetime2 is not supported. Is there any workaround that could enable me to insert pr-1753 dates in a datetime2 column?
Informatica version is 9.1.0, SQL Server 2008
If upgrading to a newer version of Informatica won't help or isn't an option, then you've got limited options. One option is to CONVERT the datetime2 to a suitable VARCHAR representation from the SQL Server side and then feed that to Informatica and let the implict casting of the value back to a suitable DATETIME do the hard work for you.
You'll need to make sure you are very careful with this though - if you end up migrating text dates such as 02/03/2015 02:33 etc - then there's a chance that if regional settings differ between databases or servers, you could import that as either 2nd of March or 3rd of Feb. It's best to use culture-invariant date formats, such as yyyy-mm-dd - that way it's always unambiguous.
-Steve
We recently moved our database from SQL Server 2005 to 2014. But now we are having an issue with how the server converts datetime from varchar.
Previously, a date string 2017-06-30 was converted correctly as July 30, but now even with the user and the database with the language set to Spanish, it still converts the date format as yyyy-dd-MM.
Is there some way to permanently change the configuration to fit the original one? One work around we found was to add SET LANGUAGE ymd at the beginning, but the amount of procedures doesn't make this feasible in a timely manner.
When using SSIS in SQL Server 2005 to convert a FoxPro database to a SQL Server database, if the given FoxPro database has a date type, SSIS assumes it is an integer type. The only way to convert it to a dateTime type is to manually select this type. However, that is not practical to do for over 100 tables.
Thus, I have been using a workaround in which I use DTS on SQL Server 2000 which converts it to a smallDateTime, then make a backup, then a restore into SQL Server 2005.
This workaround is starting to be a little annoying.
So, my question is: Is there anyway to setup SSIS so that whenever it encounters a date type to automatically assume it should be converted to a dateTime in SQL Server and apply that rule across the board?
Update
To be specific, if I use the import/export wizard in SSIS, I get the following error:
Column information for the source and the destination data could not be retrieved, or the data types of source columns were not mapped correctly to those available on the destination provider.
Followed by a list of a given table's date columns.
If I manually set each one to a dateTime, it imports fine.
But I do not wish to do this for a hundred tables.
You could make a small FoxPro program that will loop through your list of tables and write out a SQL INSERT INTO statement for each record to a .sql file which you could then open from or paste into SQL Management Studio and execute. You could then control the date formats that will work with SQL Server's date type fields.
Something similar could be done in c#.