August 3, 2012 at 1:17 pm
What is wrong with the following code?
BULK INSERT test
FROM 'myfile_'+ CONVERT(VARCHAR(20), GETDATE(), 112) + '.TXT'
WITH
(FIRSTROW = 2,
FIELDTERMINATOR = '~',
ROWTERMINATOR = '')
Thanks
August 3, 2012 at 1:22 pm
Whats the error?
August 3, 2012 at 1:30 pm
BULK insert does not allow variables , nor will it allow concatention to create the file name;
BULK INSERT BULKACT FROM 'c:\Export_o.txt' --valid
BULK INSERT BULKACT FROM 'c:\' + @path --error
BULK INSERT BULKACT FROM @path --error
so you have to switch to dynamic SQL in order to do what you are trying to do:
--bulk insert won't take a variable name, so make a sql and execute it instead:
set @sql = 'BULK INSERT BULKACT FROM ''' + @path + @filename + ''' '
+ ' WITH (
DATAFILETYPE = ''char'',
FIELDTERMINATOR = '','',
ROWTERMINATOR = ''\n'',
FIRSTROW = 2
) '
print @sql
exec (@sql)
Lowell
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply