How to programmatically import large numbers of records from a separated text file from a folder and insert into SQL Table

Aypn CNN 446 Reputation points
2022-11-01T09:43:11.007+00:00

Hi,

Can anyone provide some samples programmatically to import from a separate text file same is insert into a SQL Table with created timestamp.

Please ref my sample Bulk separate text file, it stored in D:\BulkImpFile\EM_20221031.txt (attached) 255948-em-20221031.txt
256041-ss-bulktextfile.png

ref my SQL Table

If(OBJECT_ID('tempdb..#empMaster') Is Not Null)  
Begin  
    Drop Table #empMaster  
End  
  
Create Table #empMaster  
(  
    EmpCode Varchar(10),   
    EmpName Varchar(50),   
    DOB DateTime,   
 DPImage_Path Varchar(MAX),   
 Salary Decimal(15,2),  
 CreatedOnTimeStamp DateTime  
)  
SQL Server Integration Services
SQL Server | Other
0 comments No comments
{count} votes

Answer accepted by question author
  1. ZoeHui-MSFT 41,536 Reputation points
    2022-11-02T03:16:05.73+00:00

    Hi @Aypn CNN ,

    You may use SSIS to import the data to table.

    And then you may use sql agent job to run the package so that it could be an automated operation.

    ssis-how-to-get-most-recent-file-from.html

    sql-server-agent-jobs-for-packages

    Regards,

    Zoe Hui


    If the answer is helpful, please click "Accept Answer" and upvote it.


1 additional answer

Sort by: Most helpful
  1. Olaf Helper 47,586 Reputation points
    2022-11-01T10:13:42.663+00:00

    You can use the bcp Utility to import data into SQL Server.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.