Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I read a text file with T-SQL, parse it and get some data?

Status
Not open for further replies.

passs

Programmer
Dec 29, 2003
170
RU
Hello everybody!

Does anybody know how can I using T-SQL open a text file for future parsing, getting some infoprmation, for example as a long string, parsing will be on me, for further insering into tables?

Any ideas?
Thank you!
Alex
 
Hi

Create DTS package, With ActiveXScript Task to parse the data and Data Transformation Task to load the text file.



Good Luck
Gopala Krishna Kakani

 
Hey, thanks,
but there is another way I found a few minutes ago:
declare @command varchar(250),
@filename varchar(250)

select @filename = '\\server\foo.txt'
select @command = 'TYPE ' + @filename

create table #tResults (line_id int identity, line_text varchar(800))

insert into #tResults
exec master..xp_cmdshell @command

select * from #tResults order by line_id

drop table #tResults

read row by row!
But thank you!
Alex
 
There are three native methods to insert data from a text file into SQL. BCP, Bulk Insert and DTS.

Denny
MCSA (2003) / MCDBA (SQL 2000)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top