How to read a Text file using T-SQL?

后端 未结 5 1699
迷失自我
迷失自我 2020-12-06 18:06

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

5条回答
  •  没有蜡笔的小新
    2020-12-06 18:24

    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 :

    
    
       
      
     
     
      
     
    
    

提交回复
热议问题