Unanswered: BULK insert from a text file name stored into a variable
Hello I need to write a proc to load data from txt files I receive into a table. It works fine when I specify
bulk insert.... from 'myfilename.txt'
BUT my filename will always change and I store it into a variable @filename
When I try to run the bulk insert instruction ... from @filename it doesn't work..
do you know why?
Accoding to the destructions for BULK INSERT, it takes a literal string for the file name. To sidestep this requirement, you can resort to dynamic SQL using the EXECUTE character string syntax. It isn't pretty, but it should get the job done for you.