I need to import a flat csv file with datetime column - 'ExecutionDateTime'. This column can have empty values, example :
I am importing this to an existing table with ExecutionDateTime Column is set as Datetime2.
ExecutionDateTime datetime2,
When I import using SQL Server Import Export wizard, I get value as "0001-01-01 00:00:00.0000000", for the empty row. I want it to Read NULL.
ExecutionDateTime Column is set as Datetime2.
Current behavior:
Expected :
I am using SQL Server 2012.
Any pointers?
I don't think it's possible with the wizard. But, you could use a case statement on the import...
insert into mytable
select
Id
,case when ExecutionDateTime = '' then null else ExecutionDateTime end
from --openrowset, etc...
Or, you could always fix it after the fact if the data set is small 0r you are using a staging table...
update mytable
set ExecutionDateTime = null
where ExecutionDateTime = ''
Here's an example using BULKINSERT