Problem : MySQL to MSSQL null date column

Problem : MySQL to MSSQL null date column

I am trying to convert (or transfer) a MySQL database into a MSSQL database.
I am using this statement:
select * into TEST.dbo.thefiles

from openquery(MySQL, ‘select id, file, PUDate from thefiles)
And I get the error:
An unexpected NULL value was returned for column “[MSDASQL].PUDate” from OLE DB provider “MSDASQL” for linked server “MySQL”. This column cannot be NULL.

This is because in MySQL a date can be 0000-00-00 but in Microsoft that is not a valid datetime.
The dates are 0000-00-00 on purpose because we have not yet had a date to put in them.
Is there any way that when creating the table I can allow null values in the PUDate column?
(Sorry I am kind of new to SQL statements and a full SQL query would be greatly appreciated)

Solution: MySQL to MSSQL null date column

actually, the singe quotes around the 0000% need to be 2 single quotes each time, and not double quotes…
I also forgot the ‘ at the end of the openquery …

now, the actual problem is that “cast (” needs to be “cast(” , mysql is picky about functions, the bracket needs to follow the function name without a space…

let’s see if this is any better:

select * into TEST.dbo.thefile
from openquery(MySQL, ‘select id, file, cast( case when PUDate LIKE ”0000%” THEN NULL ELSE PUDate END as date) as PU_DATE  from thefiles ‘ ) l