I want to create an export to an Excel file.
For this I use this code:
INSERT INTO OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 8.0;Database=C:\Temp\65343\file.xls;',
'SELECT group,subgroup,name_product,manufacture,unit,
retail_price,wholesale_price,info FROM [ExportSheet$]')
VALUES
('name','name','name','name','name','0.00','0.00',''),
('name','name','name','name','name','0.00','0.00','');
But I get this error:
Msg 257, Level 16, State 3, Line 2
Implicit conversion from data type varchar to varbinary is not allowed.
Use the CONVERT function to run this query.
Tell me please why i have error and how right write this code?
Your syntax looks correct to me, so I have a few observations.
That error generally means you are having a data type conversion issue — in this it looks like one of your fields in your excel file is expecting a varbinary field but is receiving a varchar field instead.
Does it work if you limit the fields to just one, say group? If so, you can figure out which field is the culprit.
Alternatively, instead of using VALUES clause, can you use a temp table:
Not sure this will help, but I’ve never used INSERT INTO OPENROWSET explicitly supplying the values — seems like it should work though.
Good luck.