I'm trying to import a CSV file to a database using the BULK command. I've created a small procedure that accepts two parameters - path to CSV file and Table to insert data to.
CREATE PROC import_excel
(@tblName VARCHAR(10), @path VARCHAR(100))
AS
DECLARE @cmd VARCHAR(200)
BEGIN
SET @cmd = 'BULK INSERT '+ @tblName +
' FROM ' + @path +
' WITH
(
FIRSTROW = 2 ,
MAXERRORS = 0 ,
FIELDTERMINATOR = '','',
ROWTERMINATOR = ''\n''
)'
EXECUTE(@cmd)
END
But I am unable to execute it. It throws Incorrect syntax near ' ' I'm pretty sure it has something to do with concatenating strings and parameters, I just can't figure out the problem.
Thank you