read file | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

read file

I can read a file (*.txt) from store procedure and insert the information in a table<br /><br />somebody to help me<br />[<img src=’/community/emoticons/emotion-6.gif’ alt=’:(‘ />]

declare @command varchar(250)
, @filename select @filename = ‘c:foo.txt’
select @command = ‘TYPE ‘ + @filename create table #tResults (line_id int identity, line_text varchar(8000) ) insert into #tResults
exec xp_cmdshell @command select * from #tResults order by line_id drop table #tResults
…or does the text file contain data delimited by commas or other symbols ? if that is the case then (1). You could rewrite Bambola’s stored proc to process the data that it reads into the temporary #results table
(2). Use the BULK INSERT statement in a stored procedure to load the data into intermediate tables. Additional code in the stored procedure would manipulate the data, perform lookups, etc.
I assumes he needs to read a "simple" file otherwise I’d suggest BCP. <img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ /><br /><br />Bambola.<br /><br />