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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 reading in a text file

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-07-22 : 08:08:30
Brad writes "I am trying to read the contents of a text file into a variable in order to get a small piece of information from the file.

I have been fiddling around with it and I can display the the file with this command.

xp_cmdshell 'type \\10.1.1.1\d$\output\\foo.txt'

but I can't seem to get it into a variable so I can parse it out. This is what I have but it doesn't work

declare @result varchar(500)
set @result = exec xp_cmdshell 'type \\10.1.1.1\d$\output\\foo.txt'
select @result

thanks in advance"

MuffinMan
Posting Yak Master

107 Posts

Posted - 2002-07-22 : 13:08:50
Throw the results into a temp table and parse as needed:

[code]
create table #tmp (RowId int primary key clustered not null, TextLine varchar(255) null)

insert #tmp (TextLine)
exec xp_cmdshell 'type \\10.1.1.1\d$\output\\foo.txt'
go

select * from #tmp
[\code]



Edited by - muffinman on 07/22/2002 13:09:16
Go to Top of Page
   

- Advertisement -