I am trying to execute bulk insert statement using sp_executesql.
I received syntax error:
Msg 102, level 15, state 1
Incorrect syntax near '\t'.
my code block are based on this link
Please review my code and advise what went wrong and how can I correct it.
declare @filepath nvarchar(500); set @filepath = N'c:\bcp\textfiles\product.txt'; declare @bulkinsert nvarchar(2000); set @bulkinsert = N'bulk insert product from ''' + @filepath + N''' with (FIRSTROW = 2, FIELDTERMINATOR = "\t", rowterminator = "\n")'; exec sp_executesql @bulkinsert;
in product.txt file, the tab key is used as field delimiter
below a sample from the text file
Note: first row is 6 columns (productname column has no value)
PRODUCTID PRODUCTNAME PRODUCTGROUPCODE PRODUCTGROUPNAME INSTOCKFLAG FULLPRICE
10001 CA CALENDAR N 15