I had a similar problem and this is how I solved it and it worked perfectly:
Step 1: create a staging table and 3 temp tables:
Create table tbl2 (col1 varchar(80))
Create table #temp1 (ctr int identity,Data1 varchar(80))
Create table #temp2 (ctr int identity,Data2 varchar(80))
Create table #temp3 (ctr int identity,Data3 varchar(80))
Step 2: Create a trigger on your staging table as follows:
Create trigger trg1 on Tbl2 for insert as
begin
Declare @variable varchar(50)
select @variable=col1 from Inserted
if Left(Ltrim(@variable),4)='User'
Insert into #temp1 select @variable
if Left(Ltrim(@variable),4)='Time'
Insert into #temp2 select @variable
if Left(Ltrim(@variable),4)='Loca'
Insert into #temp3 select @variable
end
Step 3
Import data from the file into your staging table using bulk Insert like this. Make sure you specify the fire_trigger option
BULK INSERT Northwind.dbo.Tbl2
FROM 'C:\mylogfile.txt'
WITH
(
FIELDTERMINATOR = '\n',
ROWTERMINATOR = '\n',
FIRE_TRIGGERS
)
As the bulk insert inserts rows in the staging table TBL2, the trigger populates the 3 tables.After the imports completes you can join the 3 tables to create a final table;
SELECT Data1 as 'UsersName',data2 as 'TimeLoggedIn',data3 as 'Location' Into MYFinalTable FROM
#temp1 INNER JOIN #temp2 on #temp1.counter=#temp2.counter
INNER JOIN #temp3 on #temp1.counter=#temp3.counter
Voila!!!!
Bertrandkis.