Skip to content Skip to sidebar Skip to footer

Importing A Txt File Into Sql Server With A Where Clause

I have a .txt file which is 6.00 GB. It is a tab-delimited file so when I try to load it into SQL Server, the column delimiter is tab. I need to load that .txt file into the datab

Solution 1:

Have you tried with BULK INSERT command? Take a look at this solution:

--Create temporary tableCREATETABLE #BulkTemporary
(
  Id int,
  Valuevarchar(10)
)

--BULK INSERT has no WHERE clause
BULK INSERT #BulkTemporary FROM'D:\Temp\File.txt'WITH (FIELDTERMINATOR ='\t', ROWTERMINATOR ='\n')

--Filter resultsSELECT*INTO MyTable FROM #BulkTemporary WHEREValueIN ('Row2', 'Row3')

--Drop temporary tableDROPTABLE #BulkTemporary

Hope this helps.

Solution 2:

Just do a Bulk Insert into a staging table and form there move the data you actually want into a production table. The Where Clause is for doing something based on a specific condition inside SQL Server, not for loading data into SQL Server.

Post a Comment for "Importing A Txt File Into Sql Server With A Where Clause"