ayan biswas

ayan biswas

  • NA
  • 1
  • 3.6k

Could not bulk insert. File ' @PathFileName ' does not exist.

Feb 27 2008 8:26 AM

Someone help me out .How to solve the problem.I built a stored procedure in MS SQL 2005 to bulk insert into a table by reading the .txt file. But my stored procedure throws an error.

"Could not bulk insert. File ' @PathFileName ' does not exist."

My stored given below :-

CREATE PROCEDURE [dbo].[ps_CSV_Import]
AS
 
 DECLARE @PathFileName varchar(2000)
 ----Step 1: Build Valid BULK INSERT Statement
 DECLARE @SQL varchar(2000)
 
 SELECT @PathFileName="D:\Areazone.txt"
 BEGIN
   SET @SQL = "BULK INSERT Temp FROM '"+" @PathFileName "+"' WITH (FIELDTERMINATOR = '"",""') "

 END

--Step 2: Execute BULK INSERT statement
EXEC (@SQL)

--Step 3: INSERT data into final table
INSERT mstArea(Description,Refid)
SELECT SUBSTRING(Description,2,DATALENGTH(Description)-1),
        SUBSTRING(RefId,1,DATALENGTH(RefId)-0)   
FROM Temp

--Step 4: Empty temporary table
TRUNCATE TABLE Temp

Please help me ,if someone have any solution