Reputation: 1
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
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