Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 A RETURN statement with a return value cannot be u

Author  Topic 

Sharon_DBA
Starting Member

7 Posts

Posted - 2009-07-13 : 19:14:49
Hi all,
Why am I getting "A RETURN statement with a return value cannot be used in this context." with the following:



declare @x int
declare @fname varchar (255)
declare @errorsave INT
declare @result int

set @X=0
set @fname='D:\LOG\StatusReportJob.out'
set @errorsave=0
set nocount on
while @X<10

begin
set @X=@X+1
exec master..xp_fileexist @fname, @result output

IF (@result = 1)
begin
select 'file '+@fname+' exists. Moving on...'
goto DONE
end

else

begin
select 'file '+@fname+' does not exist. Continuing to loop and wait...'
waitfor delay '00:00:01'
end
print @X
end
endloop:
set @errorsave=890
done:

RETURN @errorsave




Thanks in advance,
Sharon

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-07-13 : 19:20:04
RETURN with a value is only permitted when run inside a stored procedure.
When code is extracted and run in a query window, RETURN doesn't allow a value.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Sharon_DBA
Starting Member

7 Posts

Posted - 2009-07-13 : 22:21:21
Ah, yes...thank you very much...
Go to Top of Page
   

- Advertisement -