SQL Server datetime2 in OPENQUERY - sql

We're migrating form SQL Server 2005 to 2014 for a pretty large environment. And we've noticed that OPENQUERY behaves differently when interacting with MySQL database when it comes to datetime. Previously, it would translate just fine to DATETIME column. With 2014 (I assume started in 2008 or so), it now converts to DATETIME2 (with maximum precision). This causes problems when comparing to or inserting into DATETIME columns.
Is there a way to specify on a server-level (or specify default) for which type those will translate to? Rewriting all of the queries will be quite an undertaking, and I'd like to avoid this now, if possible (rather rewrite as we edit or introduce new things).

Try to Use VARCHAR datatype while migration of date fields, and it is always easy to Convert/Cast in various types as per need.

Related

Beside compatibility with SQL Server 2000 and 2005, is there any other issue to use datetime2

I know datetime2 is faster than datetime and also is using less storage space for the same accuracy. Do you know any other impediment to migrate my fields from datetime to datetime2 rather than compatibility with SQL Server 2000 and 2005?
Thanks in advance.
There are no downsides with using datetime2 versus datetime as long as you use datetime2 only or avoid conversions between these two data types.
There is a potentially breaking change in SQL Server 2016 with regards to value rounding when converting between these types that could be an issue depending on your code.

Error Converting varchar to Int - Sql on Server vs SQL on local PC

I have a Query requiring Varchar to be converted into INT. Iam not currently posting the query itself as I do not believe the problem to be there.
I setup the query on my home PC using a backup from the servers SQL file. I have Server 2008 R2 installed on both machines.
The Query runs 100% on my PC but gives an error converting varchar to INT when run on the server.
Iam guessing there is a setting somewhere that is not the same? I have checked Regional settings and the problem is not there. any ideas?
The problem lies in how the query is evaluated. You have no guarantee or what order parts of the query will be evaluated in, so on one machine a filter may happen after a convert, on another it could do. Or the WHERE clause conditions can be evaluated in a different order
SQL is declarative, not procedural. With SQL you ask for what you want and the query optimiser honours that how it sees fit. In a procedural language (C#, Java etc) you'd control the execution order.
The reason is full described here: Why use Select Top 100 Percent?

Oracle-to-SQL Server replication: manipulate data during replication

I've "inherited" a working Oracle (10g) to SQL Server 2005 data replication using standard SQL Server snapshot and transactional replication.
Everything works fine - as long as Oracle doesn't try to send a date that's outside the SQL Server DATETIME range (1753/1/1 to 9999/12/31). I was hoping to be able to somehow get in the middle of the data replication, check for that date range, and if necessary, tweak the Oracle date being published to be something that SQL Server 2005's DATETIME datatype can handle.
Is there any reasonably easy way to do this?? I know I could just change the target datatype to VARCHAR(19) or something like that - and I know I could upgrade to SQL Server 2008 and use the DATE or DATETIME2 datatypes to solve the issue - both options aren't viable right now (maybe in 6, 12 months or so).
Is there something I can do right now? And easily?? I cannot get too deep into Oracle to fix it here, unforutnately (that's another third-party company that doesn't like other folks fiddling around in their system).
I don't believe there's a solution to this - from what I understand, the replication process is similar to using the log reader for transactional replication, so it's a black box - it's unlikely that you could inject any code into the process, and if you could, it would be lower level code than SQL.

Why doesn't SQL Server have a pure date and pure time data type?

I have a few SQL Server tables with a datetime field that really only has to contain dates... and the fact that it's a datetime object violates data integrity, because it's possible for data to be inserted with a time - which isn't really valid for this field. The result is that we have to convert it and strip off the time every single time we use it. We've considered adding triggers to make sure that no data can even get in with a time attached... but it seems to me that this should really be part of the database software, and shouldn't need to be specifically programmed each time.
Why doesn't SQL Server have separate date and time data types? Is this going to change in the near future? Do other database platforms have this functionality?
SQL Server 2008 has DATE and TIME data types.
What version are you using?
SQL Server has a pure date and time data type since version 2008, they also added a bunch of new datetime types, now it also goes all the way back to year 1 instead of 1753

UNDEFINED data type when reading SQL database from Lotus Notes using ODBC: nvarchar

This is the second time it happens to me and before modifying a 3rd party Database structure I wanted to know if anyone knew a better solution:
I'm accessing a MS SQL Server 2008 from a Lotus Notes Agent (Notes 7) to retrieve some data. I use LSXODBC and my "Select" statement works perfect... Except that my agent cannot "understand" Nvarchar SQL Field types. Any other data types work ok (can get the values from number and dates fields without a problem).
It took me a while to figure it out, and I couldn't find a solution (other than modifying the field types on the SQL table to Varchar instead of nVarchar)
I could replicate this both in MS SQL 2005 and 2008.
Last "elegant" solution was to create an SQL view -instead of modifying table structure- with the varchar types instead of nvarchar. Works ok but I have to create a view for each table I'm retrieving data from.
I tried to set the Field type using FieldExpectedDataType Method but didn't work. Still got a DB_TYPE_UNDEFINED.
I thought there might be some configuration issues? or maybe I'm using an old LN Version / ODBC Driver version?
Any hint would be greatly appreciated.
Thank you in advance.
Diego
An old ODBC driver may not support unicode. It was not added until SQL Server 2000 (I'm fairly sure)