Hi @Anirudh Mukherjee ,
Welcome to Microsoft Q&A!
Please always use a staging/load table for bulk actions. Then you could process, clean, scrub etc the data before flushing to the real table.
Please refer below example:
Use below txt.
CREATE TABLE dbo.DEMO
(DEMO VARCHAR(100))
BULK INSERT dbo.DEMO FROM 'C:\SQL\Demo.txt'
WITH
(
--FIELDTERMINATOR = ':',
ROWTERMINATOR = '\n',
--TABLOCK,
CODEPAGE = 'US'
);
SELECT * FROM dbo.DEMO
Output:
DEMO
11/9/2015 12:00:00 AM:india.delhi@gmail.com:12/15
11/10/2015 12:00:00 PM:india.delhi1@gmail.com:12/16
Then insert into USA table.
CREATE TABLE DBO.USA
([DATETIME] DATETIME
,emailid VARCHAR(100),
dob VARCHAR(10))
INSERT INTO DBO.USA
SELECT LEFT(DEMO,CHARINDEX('M:',DEMO))
,SUBSTRING(DEMO,CHARINDEX('M:',DEMO)+2,CHARINDEX('com:',DEMO)-CHARINDEX('M:',DEMO)+1)
,REVERSE(LEFT(REVERSE(DEMO),CHARINDEX(':',REVERSE(DEMO))-1))
FROM dbo.DEMO
SELECT * FROM DBO.USA
Output:
DATETIME emailid dob
2015-11-09 00:00:00.000 india.delhi@gmail.com 12/15
2015-11-10 12:00:00.000 india.delhi1@gmail.com 12/16
If above is not working, please provide your txt and expected output.
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.