我收到'无效列名'@ FileName-- value''错误执行下面的存储过程。我试图找到问题的根本原因而没有运气......请告诉我我错在哪里。
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
答案 0 :(得分: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 +'''
答案 1 :(得分: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 + ''''
你必须在撇号'
之间传递值。