SP报价错误

时间:2014-06-10 10:05:43

标签: sql sql-server

任何人都可以使用以下代码行帮助我。我一直在'\'附近收到错误的语法错误:

 SET @filename = 
 ''BULK INSERT dbo.Tmp_Table 
  FROM ''\\SQL-300\ConvertedFiles\London\Figures\' 
  + @YEAR + '_' + @CLIENT+ '_' + @POLICYID + '.CSV'' 
  WITH (FIELDTERMINATOR = '','', ROWTERMINATOR = ''\n'', KEEPNULLS)''

2 个答案:

答案 0 :(得分:0)

试试这个

SET @filename ='BULK INSERT dbo.Tmp_Table 
  FROM ''\\SQL-300\ConvertedFiles\London\Figures\' 
  + @YEAR + '_' + @CLIENT+ '_' + @POLICYID + '.CSV'' 
  WITH (FIELDTERMINATOR = '','', ROWTERMINATOR = ''\n'', KEEPNULLS)'

答案 1 :(得分:0)

你可以尝试这样的事情......

DECLARE @filename NVARCHAR(MAX);
DECLARE @Year     INT;
DECLARE @CLIENT   INT;
DECLARE @PLICYID  INT; 

SET @filename =  N'BULK INSERT dbo.Tmp_Table 
                  FROM ''\\SQL-300\ConvertedFiles\London\Figures\@YEAR_@CLIENT_@POLICYID.CSV '' 
                  WITH 
                    (FIELDTERMINATOR = '',''
                    ,ROWTERMINATOR = ''\n''
                    ,KEEPNULLS)'

EXECUTE  sp_executesql @filename
                      ,N'@Year INT, @Client INT, @PLICYID INT'
                      ,@Year
                      ,@CLIENT   
                      ,@PLICYID