BULK INSERT Incorrect syntax near the keyword 'with'

Hi experts,

@IFile nvarchar(250)
AS

BULK
INSERT LogTmp
FROM '' + @IFile + ''
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
FIRSTROW = 2,
FIRE_TRIGGERS
)

gives me error
Incorrect syntax near the keyword 'with'
JoeUSAsked:
Who is Participating?
 
Anthony PerkinsConnect With a Mentor Commented:
You cannot use it like that.  In order to make the data_file dynamic you will have to make the whole statement dynamic, something like this (untested):
DECLARE @SQL nvarchar(1000)

SET @SQL =
'BULK INSERT LogTmp
FROM ' + @IFile + '
WITH
(
FIELDTERMINATOR = '','',
ROWTERMINATOR = ''\n'',
FIRSTROW = 2,
FIRE_TRIGGERS
)'

Open in new window

0
 
Anthony PerkinsCommented:
Oops I missed the last step:
EXEC (@SQL)
0
 
JoeUSAuthor Commented:
Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.