Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A RETURN statement with a return value cannot be used in this context

Status
Not open for further replies.

robbiedoo

Programmer
Joined
Apr 2, 2007
Messages
2
Location
CA
A RETURN statement with a return value cannot be used in this context

I get that error, When I try this:
Code:
Declare @OrderNumber int, @Error_Count int, @today datetime 

Select @today = getdate()
Select @OrderNumber = (Select MAX(OrderNumber) from Orders)
Select @OrderNumber = (Sum(@OrderNumber + 1))

begin transaction
	Insert into Orders (OrderNumber, OrderDate, EmployeeId, TaxGST, TaxPST, TaxHST, OrderCost, OutletId)
Values	
(@OrderNumber, @today, 59, 26.6, 26.6, 0.00, 78.80, 1	

Select @Error_Count = @@error
if @Error_Count > 0
begin
     raisError('Order addition was unsuccessful"',16,1)
     rollback transaction
end
	
else
     begin
     commit transaction
     return @OrderNumber
end
 
You appear to be missing a close parenthesis on this line...

[tt][blue](@OrderNumber, @today, 59, 26.6, 26.6, 0.00, 78.80, 1[!])[/!][/blue][/tt]


-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Yea, I guess it got lost when I posted my code...

There IS a close parenthesis there, well in my query there is...
 
Have you tried making this a stored procedure?

Code:
[COLOR=blue]Create[/color] [COLOR=blue]Procedure[/color] [!]Blah_Proc[/!]
[COLOR=blue]AS[/color]
[COLOR=blue]SET[/color] [COLOR=#FF00FF]NOCOUNT[/color] [COLOR=blue]ON[/color]

Declare @OrderNumber [COLOR=blue]int[/color], @Error_Count [COLOR=blue]int[/color], @today [COLOR=#FF00FF]datetime[/color] )
[COLOR=blue]Select[/color] @today = [COLOR=#FF00FF]getdate[/color]()
[COLOR=blue]Select[/color] @OrderNumber = ([COLOR=blue]Select[/color] [COLOR=#FF00FF]MAX[/color](OrderNumber) [COLOR=blue]from[/color] Orders)
[COLOR=blue]Select[/color] @OrderNumber = (Sum(@OrderNumber + 1))

[COLOR=blue]Select[/color] @OrderNumber
[COLOR=blue]return[/color]

[COLOR=blue]begin[/color] [COLOR=blue]transaction[/color]
    [COLOR=blue]Insert[/color] [COLOR=blue]into[/color] Orders (OrderNumber, OrderDate, EmployeeId, TaxGST, TaxPST, TaxHST, OrderCost, OutletId)
	[COLOR=blue]Values[/color] (@OrderNumber, @today, 59, 26.6, 26.6, 0.00, 78.80, 1    )

[COLOR=blue]Select[/color] @Error_Count = @@error

[COLOR=blue]if[/color] @Error_Count > 0
	[COLOR=blue]begin[/color]
	     [COLOR=blue]raisError[/color]([COLOR=red]'Order addition was unsuccessful"'[/color],16,1)
	     [COLOR=blue]rollback[/color] [COLOR=blue]transaction[/color]
	[COLOR=blue]end[/color]
[COLOR=blue]else[/color]
     [COLOR=blue]begin[/color]
	     [COLOR=blue]commit[/color] [COLOR=blue]transaction[/color]
		[COLOR=blue]return[/color] @OrderNumber
	[COLOR=blue]end[/color]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top