I have files that I need to bulk insert into SQL server:
@Date char(8) = '20200429' *--this is a specific file variable*
so the paths are as follows:
root path: @ROOT = 'G:\app\Data\table-dump\'
filepath: @FILEPATH = @date+'\'+@Date+'-230000-file.txt'
fullpath: @FULLPATH = @ROOT + @FILEPATH
I want to run a bulk insert into a table called dbo.TableDump_IMPORT
SO I constructed this:
DECLARE @BULKINSERT as varchar(max)
SET @BULKINSERT= 'BULK INSERT dbo.TableDump_IMPORT FROM ' + @FULLPATH + ' WITH ( FIRSTROW = 2, FIELDTERMINATOR = ''|'', ROWTERMINATOR = ''0x0A'')'
EXEC @BULKINSERT
When I run the command I get this error:
The name 'BULK INSERT dbo.TableDump_IMPORT FROM G:\app\Data\table-dump\20200429\20200429-230000-file.txt WITH ( FIRSTROW = 2, FIELDTERMINATOR = '|', ROWTERMINATOR = '0x0A')' is not a valid identifier.
How do I get it to just execute the BULK INSERT command?
EXEC (@BULKINSERT)