[dba-SQLServer] Open a text file from SQL Server

Arthur Fuller artful at rogers.com
Thu Oct 7 08:32:47 CDT 2004


Billy Pang wrote:

> there is:
>
> declare @file_location varchar(255)
> declare @exec_stat varchar(255)
> SET @file_location = 'C:\myFile.txt'
> SET @exec_stat = 'type ' + @file_location
> EXEC master.dbo.xp_cmdshell @exec_stat
>
> note: it's not perfect because text in the variable is "word wrapped".
>
> Billy
>
Does this give me the contents of the file in a variable? That's what I 
really need. Maybe it does, but I don't see how, or which variable will 
contain the returned text.

Arthur




More information about the dba-SQLServer mailing list