I am running SQL Server 2012 and I have set up a SQL Server Agent job which will basically run a SQL query on the database and export the output to an Excel file (with xlsx extension).
When I 'parse' the query in the 'Job Properties' window to test whether my query will be running fine, I get the message 'The command was successfully parsed!'
However when I check the result of the scheduled job, it is showing me that it has failed. The error log gives the following details:
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" could not INSERT INTO table "[Microsoft.ACE.OLEDB.12.0]". [SQLSTATE 42000] (Error 7343) OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "Multiple-step OLE DB operation generated errors. Check each OLE DB status value if available. No work was done.". [SQLSTATE 01000] (Error 7412) OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "No current record."
My SQL query stands as follows:
INSERT INTO OPENDATASOURCE (
'Microsoft.ACE.OLEDB.12.0',
'Data Source=c:\test\myfile2.xlsx;Extended Properties=Excel 12.0 Xml')...[Sheet1$]
SELECT TOP 100 ReservationStayID,NameTitle,FirstName,LastName,ArrivalDate,DepartureDate FROM [GuestNameInfo]
I have already created the file 'myfile2.xlsx' in C:\test folder and that Excel file contains the column names from the SQL query above as their column headers. I am expecting the SQL job to fill in the Excel table with the output of the SQL query.
Any help on the issue or any pointers on whether I am doing something wrong here would be highly appreciated.