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

CREATE TABLE #TextData
(
Text    VARCHAR(MAX)
)

DECLARE    @sqlcmd VARCHAR(1000)

 — Reading Data

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

INSERT INTO #TextData

EXEC master.dbo.xp_cmdshell @sqlcmd

— Displaying Result

SELECT    FROM    #TextData
GO

— Drop TEMP Table

DROP TABLE #TextData

Advertisements
Comments
  1. ashish says:

    Thanks for sharing valuable information.Nice article.

    Like

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s