I'm trying to create a stored procedure to import from CSV
. Everything works if I have a hard coded file path, but I want to take a file path as a parameter. When I try SQL Sever Management Studio generates an error:
Incorrect syntax near '@filePath'.
(In fact, if I put anything but a pure string(eg. 'C:'+'/dir'
) it gives an error.)
This is a simplified version of my code:
Create procedure [importFile](@filePath varchar(Max))
AS
BEGIN
create table #Temp
(
row1 int,
row2 varchar(5),
row3 bit
)
BULK insert
#Temp
from @filePath
With(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
...
END
Any explanation?