Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-08-12 : 07:52:53
|
writes "Hello,I have a plain text file called Orders.txt with the following three lines:Line1, abcLine2, defLine3, hijI'm trying to read that text and put it in a table. I'm using the sp_oamethod call as stated below. The code runs and reports that it was successful, but when I query the table it is empty and even the 'print' command doesn't print anything. My goal is to parse each line, separating each csv value and insert into a field on a table. The code below is just for reading the file and seeing if anything comes out but that's not working. Seems simple enough, but I can't see what I might be missing. Any help is appreciated.Thanks in advance!--PhBdeclare @objFSys intdeclare @objFile intdeclare @blnEndOfFile intdeclare @strLine varchar(40)CREATE TABLE #mytesttable (sometext text)exec sp_OACreate 'Scripting.FileSystemObject', @objFSys outexec sp_OAMethod @objFSys, 'OpenTextFile', @objFile out, 'C:\orders.txt', 1exec sp_OAMethod @objFile, 'AtEndOfStream', @blnEndOfFile outwhile @blnEndOfFile=0 beginexec sp_OAMethod @objFile, 'ReadLine', @strLine outselect @strLineINSERT INTO #mytesttable (sometext) VALUES(@strLine)print @strLineexec sp_OAMethod @objFile, 'AtEndOfStream', @blnEndOfFile outendexec sp_OADestroy @objFileexec sp_OADestroy @objFSysselect * from #mytesttable" |
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2005-08-12 : 07:53:19
|
Why not just use bcp or BULK INSERT to import the data? It's a lot easier. |
 |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2005-08-12 : 09:12:37
|
If the print is not doing anything, maybe this condition is not true when the while loop starts:while @blnEndOfFile=0CODO ERGO SUM |
 |
|
|
|
|
|
|