DECLARE @path text;
SET @path = 'c:\bulk'
BULK INSERT [HumanResources].[Employee] FROM -- I Want to use the variable here !!
WITH (
CHECK_CONSTRAINTS,
CODEPAGE='ACP',
DATAFILETYPE='widechar',
FIELDTERMINATOR='\t',
ROWTERMINATOR='\n',
KEEPIDENTITY,
TABLOCK
);
答案 0 :(得分:1)
DECLARE @path nvarchar(2000);
SET @path = 'c:\bulk.(extension)';
DECLARE @sql NVARCHAR(MAX) =
'''BULK INSERT [HumanResources].[Employee] FROM' + @path + '
WITH (
CHECK_CONSTRAINTS,
CODEPAGE=''ACP'',
DATAFILETYPE=''widechar'',
FIELDTERMINATOR=''\t'',
ROWTERMINATOR=''\n'',
KEEPIDENTITY,
TABLOCK
)'''
EXECUTE sp_executesql(@sql)
答案 1 :(得分:0)
这个查询怎么样?使用动态查询来执行查询。只知道单引号。
DECLARE @path nvarchar(2000);
DECLARE @sql nvarchar(2000);
SET @path = 'c:\bulk.txt'
set @sql = 'BULK INSERT [HumanResources].[Employee] FROM ''' + @path + ''' WITH (CHECK_CONSTRAINTS, CODEPAGE=''ACP'',
DATAFILETYPE=''widechar'',
FIELDTERMINATOR=''\t'',
ROWTERMINATOR=''\n'',
KEEPIDENTITY,
TABLOCK
)'
print @sql
exec sp_executesql @sql