I'm trying run BULK INSERT in a loop. Loop through each file in some directory ends with no of particular file. Below is my solution
DECLARE @startFlag INT
DECLARE @endFlag INT
DECLARE @fileName varchar(50)
SET @startFlag = 1
SET @endFlag = 10
WHILE (@startFlag <= @endFlag)
BEGIN
SET @fileName = 'c:\path to file\filename_' + cast(@startFlag as varchar) + '.csv'
BULK
INSERT dbo.Intraday
FROM @fileName
WITH
(
FIELDTERMINATOR = '|',
ROWTERMINATOR = '\n'
)
SET @startFlag = @startFlag + 1
END
GO
but seems don't work. Is there anything I've overlooked or another missing stuff I can fix this issue?