存储过程参数的连接问题
一个存储过程有个参数 @FileAddress ,在 BULK INSERT InsertData FROM @FileAddress 这行中,提示我 :@FileAddress附近有语法错误,不知道如何写是正确的,请大家帮助,存储过程如下
CREATE PROCEDURE dbo.sp_Zhoubin_InsertTable (
@FileAddress varchar(255) --文件路径
)
AS
begin
BULK INSERT InsertData FROM @FileAddress --问题就在这里
WITH
(
FIELDTERMINATOR = ', ',
ROWTERMINATOR = '\n ',
FIRE_TRIGGERS
)
end
GO
------解决方案--------------------Try(未测试):
CREATE PROCEDURE dbo.sp_Zhoubin_InsertTable (
@FileAddress varchar(255) --文件路径
)
AS
begin
exec( '
BULK INSERT InsertData FROM '+@FileAddress+ '
WITH
(
FIELDTERMINATOR = ' ', ' ',
ROWTERMINATOR = ' '\n ' ',
FIRE_TRIGGERS
)
')
end
GO
------解决方案--------------------CREATE PROCEDURE dbo.sp_Zhoubin_InsertTable(@FileAddress varchar(255))
AS
BEGIN
declare @sql varchar(8000)
set @sql= '
BULK INSERT InsertData FROM ' ' '+@FileAddress+ ' ' '
WITH
(
FIELDTERMINATOR = ' ', ' ',
ROWTERMINATOR = ' '\n ' ',
FIRE_TRIGGERS
) '
exec(@sql)
END
GO