There are several things you need to know to be able to do this.
- How to enable ad hoc queries.
This guy enable-Ad-Hoc-Distributed-Queries shows you how. - How to format the driver string and specify your directory and filename. Like this:
OpenRowset('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=c:\MyDirectoryName;','select * from MyTextFile.txt') - How to create a text file in the right format. This format works:
"ColumnName1","ColumnName2"
"value11", "value21"
"value21", "value22"
There. That was only slightly unreasonably difficult. Now you can
Select * from OpenRowset('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)}; DefaultDir=c:\MyDirectoryName;','select * from MyTextFile.txt')
and
Insert into OpenRowset('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)}; DefaultDir=c:\MyDirectoryName;','select * from MyTextFile.txt') Values ('Col1', 'Col2')
INSERT will not work though 🙁
The requested operation could not be performed because OLE DB provider “MSDASQL” for linked server “(null)” does not support the required transaction interface.
Let me try it again on a different machine and see if I can work anything out …