What\'s the best way to read a text file using T-SQL? I\'ve seen the BULK INSERT and many different functions but non of them are what I\'m looking for.
I need to r
This can be done using FORMATFILE .When using format file you can skip the columns. there are many more advantages of using format file.
Below query will bulk load the lines into field Line.
CREATE TABLE TextFile
(
[Line] varchar(500) ,
[FileName] varchar(100) ,
[RecordDate] DATETIME DEFAULT GETDATE(),
[RecordID] INT IDENTITY(1,1) ,
)
BULK INSERT TextFile FROM 'C:\FILE.TXT'
WITH (FORMATFILE = 'C:\FILEFORMAT.XML')
Format File used in the above query is :