Sunday, December 6, 2009

BULK INSERT : From Text File to SQL Temp Table/Table

Temporary table:
DECLARE @filename NVarChar(100)
SET @filename = 'C:\DELL\Country.txt'
CREATE TABLE #tempfile (line varchar(8000))
EXEC ('bulk INSERT #tempfile FROM "' + @filename + '" WITH (CODEPAGE = ''RAW'')')
select * from #tempfile
DROP TABLE #tempfile


Normal Table:
DECLARE @filename NVarChar(100)
SET @filename = 'C:\DELL\Country.txt'
CREATE TABLE Country (line varchar(8000))
EXEC ('bulk INSERT Country FROM "' + @filename + '" WITH (CODEPAGE = ''RAW'')')
SELECT * FROM Country


No comments:

Post a Comment