Question

My setup is as follows. I have a MySQL database (5.5.34) which I linked to MS SQL via ODBC as "linked server" using MySQL ODBC 5.2 Driver.

MySQL query is as follows:

SELECT
CASE WHEN start = "0000-00-00" THEN NULL else start END as start,
CASE WHEN finish = "0000-00-00" THEN NULL else finish END as finish
FROM students

When run in phpmyadmin on the source server as a result I get a bunch of rows, some with dates and some with NULL in the start and/or finish columns. So far so good.

Now I try to put this into openquery and run the whole think from SQL Server via SQL Server Management Studio.

SELECT *    
FROM openquery(OLDSYSTEM, '
    SELECT
    CASE WHEN start = "0000-00-00" THEN NULL else start END as start,
    CASE WHEN finish = "0000-00-00" THEN NULL else finish END as finish
FROM students')

Now all the start and finish are null. I am baffled by this :/ If someone solved this problem before I would appreciate a hint.

Was it helpful?

Solution

It turns out that the problem was in the fact that MsSQL is able to store date in Date column that does not translate to date ie. 00 in month and/or 00 in day section.

In other words the dates we're all similar to 2014-12-00 or 2013-00-00 - I just haven't noticed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top