Read a text file from the Windows system

A script that will read a text file from the Windows system into SQL Server.

Here's a script that will read a text file from the Windows system into SQL Server:

CREATE PROC Sp_EnterTextFile @filename sysname 
as 
BEGIN 
   SET nocount ON 
   CREATE TABLE #tempf (line varchar(8000)) 
   EXEC ('bulk INSERT #tempf FROM "' + @filename + '"') 
   SELECT * FROM #tempf 
   DROP TABLE #tempf 
END 
GO 

For More Information

  • What do you think about this tip? E-mail us at tdichiara@techtarget.com with your feedback.
  • The Best SQL Server Web Links: tips, tutorials, scripts, and more.
  • Have an SQL Server tip to offer your fellow DBA's and developers? The best tips submitted will receive a cool prize--submit your tip today!
  • Ask your technical SQL Server questions--or help out your peers by answering them--in our live discussion forums.
  • Check out our Ask the Experts feature: Our SQL, Database Design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.

This was last published in December 2001

Dig Deeper on SQL Server Database Modeling and Design

PRO+

Content

Find more PRO+ content and other member only offers, here.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchBusinessAnalytics

SearchDataCenter

SearchDataManagement

SearchAWS

SearchOracle

SearchContentManagement

SearchWindowsServer

Close