I have data in a simple txt file, a trying to query it (to put it in a table) but when I use
select *
from OPENROWSET('MSDASQL',
'Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=C:\DB\;Extensions=TXT;',
'select * from data.txt ');
I get the rows but all are NULL because (i think) there is no field terminator and is in UTF-16LE format, in the TXT all the fields are know by the character count, example:
FIELD1FIELD2FIELD3FIELD4FIELD5FIELD6
FIELD1FIELD2FIELD3FIELD4FIELD5FIELD6
FIELD1FIELD2FIELD3FIELD4FIELD5FIELD6
FIELD1FIELD2FIELD3FIELD4FIELD5FIELD6
To make things even worse, the file is in UTF-16LE but I need it in UTF-8 (or change the format within sql 2005) so that openrowset will work
And when I use
SELECT * FROM OPENROWSET ( BULK 'C:\DB\data.txt', SINGLE_NCLOB) AS BinFile
I get all the data but in a single row 🙁
Thanks in advance
ps: also used sp_addlinkedserver and didnt work
Thank you guys for your time and brains to try to crack up this problem, finally got it solved with:
SUBSTRING to get the data from a file that is not limited by nothing
CharacterSet=unicode to enable the DB engine to read from a specific character set of the file
Thanks!!!!!!!!!
ps: In http://msdn.microsoft.com/en-us/library/bb177651.aspx found the details on the attribute “CharacterSet”, the bad thing is that in the manual for OPENROWSET dosent says a thing about this http://msdn.microsoft.com/en-us/library/ms190312.aspx >:(