尝试通过引入全局常量来改进某些tsql批量插入代码:
declare @folder varchar(max)
declare @fileLocation varchar(max)
set @folder = 'C:\SomeFolder\'
set @fileLocation = @folder + 'Data.txt';
BULK INSERT #Table
FROM ''' + @fileLocation + '''
WITH (
FIRSTROW = 2,
FIELDTERMINATOR = '\t',
ROWTERMINATOR = '\n'
);
尝试FROM代码的每个变体都没有成功。有任何想法吗?感谢。
答案 0 :(得分:1)
您可以将其转换为动态SQL:
declare @folder varchar(max)
declare @fileLocation varchar(max)
set @folder = 'C:\SomeFolder\'
declare @sql varchar(max)
set @fileLocation = @folder + 'Data.txt';
set @sql = 'BULK INSERT #Table
FROM ''' + @fileLocation + '''
WITH (
FIRSTROW = 2,
FIELDTERMINATOR = ''\t'',
ROWTERMINATOR = ''\n''
);'
exec(@sql)