Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

I am facing issue while executing stored procedure,please help me to solve this,

'MUST DECLARE SCALAR VARIABLE @FILENAME
SQL
USE [Pro4SBCR]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
 
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 = "" 
--DECLARE @FileName Varchar(50)

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 CAUSING 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
Posted
Updated 30-Sep-13 14:54pm
v2
Comments
mgoad99 30-Sep-13 13:59pm    
One quick thing i noticed, above the line commenting out declaring @fileName
SET @Image_Path = ""

You use double quotes "" try single quotes instead ''

Maybe that is the cause of you problem?

1 solution

Hello there,

I think I found your problem:

In this line:
SQL
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'

you have included the @FileName paramter inside the dynamic sql, when it executes it won't know where the parameter was declared, @strSql1 is unaware of the fact that the @FileName is being passed to the stored procedure as a parameter. Anyway, you need to add the value that @FileName parameter contains to @strSql1, like this:
SQL
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


if it gives a syntax error, try casting @FileName as varchar in this statement.

Hope it helps, good luck.

Azee...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900