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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading text from a stored procedure.

Status
Not open for further replies.

MarkWilliamson

Programmer
Apr 1, 2002
34
US
Another rookie question.. :)

I have a file x.txt which basically contains a file listing of a directory. I just want to be able to open the file and read each line individually from a stored procedure. Is there a simple way to accomplish this ?

Thanks in advance to all who reply !
 
I would first create a temp table to handle each line of text in your x.txt file ...

Code:
CREATE TABLE #ReadFile (
	[RF_Key] [int] IDENTITY (1, 1) NOT NULL ,
	[LineOfText] [varchar] (2000) NULL
) ON [PRIMARY]
I would then run this code to populate the temp table w/ the x.txt file. 1 record will be created for each line in the file.
Code:
INSERT INTO #ReadFile EXEC Master.dbo.xp_cmdshell 'type C:\x.txt'

Now you can use a WHILE statement to read each record/text line by incrementing the RF_key from 1 by one.

You can also run a SELECT just to see what the table will look like ...

Code:
SELECT * FROM #ReadFile

Thanks

J. Kusch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top