I have a .NET App from which I am calling 2 stored procedures. One of these stored procedures is a Bulk Insert, to which I will pass in the appropriate filename, table name, and delimiter from the .NET app. After some research, I found out that I would need to use dynamic SQL to allow for variable filenames in a BULK INSERT
.
The code I have now reads:
CREATE PROCEDURE transfer_data
@file_path VARCHAR, @t_name VARCHAR, @delimeter VARCHAR
AS
BULK INSERT @t_name
FROM @file_path
WITH (
FIELDTERMINATOR = @delimeter,
ROWTERMINATOR = '\n'
);
How would I refactor this? Other examples that I've seen (BULK INSERT with variable file name) are still setting the variable in the query, however I will be passing the parameters from my .NET App.