0

我在存储过程下面执行时收到“无效的列名'@FileName--值'”错误。我试图找到问题的根本原因,但没有运气......请告诉我我哪里错了。

ALTER PROCEDURE [dbo].[usp_ICLExtract_GetFile]

 @FileName Varchar(50),     
 @Image_Path    Varchar(50) Output,     
 @FIleNameList  varchar(4096) OUTPUT
AS
BEGIN

    SET NOCOUNT ON
    DECLARE @strProcName  varchar(255) 
    SET @strProcName = 'usp_ICLExtract_GetFile'
    DECLARE @strSQL1 varchar(1024), @strSQL2 varchar(1024)
    DECLARE @strFileName Varchar(50)
    DECLARE @intErrorReturn int 
    SET @intErrorReturn = 0
    SET @FileNameList = ''
    SET @Image_Path = ''    
    SET @strSQL1 = N'SELECT tbl_ICLExtCashLetter.Image_Path from  tbl_ICLExtCashLetter  INNER JOIN tbl_ICLExtFile  on [tbl_ICLExtCashLetter].ICLExtFileUID = [tbl_ICLExtFile].ICLExtFileUID  where tbl_ICLExtFile.FileName = ' + @FileName --This line cause error

    /*==============================================================================
    * Run the query'
    *==============================================================================*/
    SET @strSQL2 = 'DECLARE curCategory INSENSITIVE SCROLL CURSOR FOR ' + @strSQL1
    EXEC(@strSQL2)
    SELECT @intErrorReturn = @@ERROR
    IF (@intErrorReturn <> 0) GOTO usp_ICLExtract_GetFile_Error
    OPEN curCategory
    SELECT @intErrorReturn = @@ERROR
    IF (@intErrorReturn <> 0) GOTO usp_ICLExtract_GetFile_Error
    FETCH NEXT FROM curCategory INTO @strFileName
    WHILE (@@FETCH_STATUS <> -1)
    BEGIN
    SET @FileNameList = @FileNameList + @strFileName + ';'
    SET @Image_Path  = @Image_Path  + 1
    FETCH NEXT FROM curCategory INTO @strFileName
    END
    CLOSE curCategory
    DEALLOCATE curCategory
    RETURN(0)   
usp_ICLExtract_GetFile_Error:
    RETURN(@intErrorReturn)
END
4

2 回答 2

1

用这个替换行

 SET @strSQL1 = N'SELECT tbl_ICLExtCashLetter.Image_Path from  tbl_ICLExtCashLetter  INNER JOIN tbl_ICLExtFile  on [tbl_ICLExtCashLetter].ICLExtFileUID = [tbl_ICLExtFile].ICLExtFileUID  where tbl_ICLExtFile.FileName = ''' + @FileName +'''
于 2013-10-01T07:25:08.560 回答
0

将您的查询更改为:

N'SELECT tbl_ICLExtCashLetter.Image_Path from  tbl_ICLExtCashLetter  
INNER JOIN tbl_ICLExtFile  on [tbl_ICLExtCashLetter].ICLExtFileUID = 
[tbl_ICLExtFile].ICLExtFileUID  where tbl_ICLExtFile.FileName = ''' + @FileName + ''''

你必须在撇号之间传递值'

于 2013-10-01T07:20:05.817 回答