Import Text file in a Table

Posted: August 29, 2014 by Virendra Yaduvanshi in Database Administrator
Tags: , , , , ,

As we know there are many options to import TEXT file data in a SQL Server Database table like using Import/Export Wizard, SSIS, BULK Insert command or OPENROWSET method, apart from these we can also use xp_cmdshell to import text file in a Table as,

— Create a TEMP Table


DECLARE    @sqlcmd VARCHAR(1000)

 — Reading Data

SET @sqlcmd ‘TYPE E:\Letter.txt’


EXEC master.dbo.xp_cmdshell @sqlcmd

— Displaying Result

SELECT    FROM    #TextData

— Drop TEMP Table


  1. ashish says:

    Thanks for sharing valuable information.Nice article.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s