I am trying to do a bulk insert but the @CSVPath is not resolving.
declare @path varchar(255)
set @path = 'C\CSVPath.csv';
BULK INSERT #mytable FROM @CSVPath <-- Error line
WITH ( FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' );
I've tried
FROM ''' + @CSVpath + '''
If I hard code the path it works. If I wrap it all in a SET statement and execute it works.
declare @sql varchar(max)
set @sql = 'BULK INSERT #mytable FROM ''' + @CSVPath + ''' WITH ...
exec (@sql)
However, I cannot do it this way and need to it the first method but it doesn't seem to be resolving and cannot figure how to get it to work.