Hi;
I have a problem about reading .txt file from sql stored procedure.
Everyday an application automatically export a .txt file into a folder in the server.
If i delete the blanks in the end of file the procedure works very well and i can import the content of .txt into T_TABLE.
But if i don't do it i take this error;
"Msg 4832, Level 16, State 1, Procedure Import_Data, Line 36
Bulk load: An unexpected end of file was encountered in the data file.
I have to say this, i have no chance to delete these blanks in the end of file every day, and like i said it is being exported automatically.
Please help me, how i can solve this error? My procedure is below;
GO
/****** Object: StoredProcedure [dbo].[Import_Data] Script Date: 12/05/2014 12:23:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Import_Adherence]
AS
BEGIN
SET NOCOUNT ON;
IF OBJECT_ID('TEMPDB..#TempTable') IS NULL
BEGIN
CREATE TABLE #TempTable ([date] nvarchar(max) NULL, [TZ] nvarchar(max) NULL, [custID] nvarchar(max) NULL)
BULK INSERT #TempTable FROM 'C:\Users\cy\Desktop\test\data.txt'
WITH
(
ROWTERMINATOR = '\n',
FIELDTERMINATOR = '|',
FIRSTROW = 4
)
END
INSERT INTO T_TABLE ([date], [TZ], [custID])
SELECT [date], [TZ], [custID] FROM #TempTable;
END
You can see what i meaned with the blanks in the end of file.