Question

I have two .txt files. The first file (out.txt) has data as below:

empno,ename
'7369','SMITH'
'7499','ALLEN'
'7521','WARD'
'7566','JONES'
'7654','MARTIN'
'7698','BLAKE'
'7782','CLARK'

And my second file (Output.txt) has data as below:

empno,ename,hiredate,comm
'7369','SMITH','1980-12-17',NULL
'7499','ALLEN','1981-02-20','300.00'
'7521','WARD','1981-02-22','500.00'
'7566','JONES','1981-04-02',NULL
'7654','MARTIN','1981-09-28','1400.00'
'7698','BLAKE','1981-05-01',NULL
'7782','CLARK','1981-06-09',NULL

Now when I execute the following statement for the first file, I get my desired output:

SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','Text;Database=D:\Data Migration;','SELECT * FROM out.txt'

But when I execute the same code for the second file, I get an error:

SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','Text;Database=D:\Data Migration;','SELECT * FROM Output.txt'

The error that I get is:

Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" reported an
error. The provider did not give any information about the error.

Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing the query "SELECT * FROM Output.txt" for execution
against OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)". 

What I understand is that, since my second file has some NULL values that would be the reason for the error. So can some one help me in handling NULL in this case?

Was it helpful?

Solution

You can use the ISNULL option and replace with your desired value.

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