Kaskrob
Kaskrob

Reputation: 1

How can i bulk insert with the filename changing

So the problem is this I get a csv file everyday. How can I import the the csv file without the filename being hardcoded. here is the code I'm using now

  BULK INSERT [dbo].[MyData]
  FROM 'input.csv'
  WITH ( 
  DATA_SOURCE = 'AzureBlob',
  FORMAT      = 'CSV',
  FIRSTROW    = 2
  );
  END

Upvotes: 0

Views: 123

Answers (1)

euTIMER
euTIMER

Reputation: 751

You need to use Dynamic SQL. Try with this code:

DECLARE @FilePath Varchar(200)
SET @FilePath = 'C:\YOUR PATH HERE\input.csv'
EXEC(BULK INSERT [dbo].[MyData]
FROM '''+ @FilePath +'''
  WITH ( 
  DATA_SOURCE = 'AzureBlob',
  FORMAT      = 'CSV',
  FIRSTROW    = 2)

I hope this helps you!

Upvotes: 1

Related Questions