1

This question already has an answer here:

Could anyone shed some light on this error for me? To a beginner of course. This will probably be no more than a simple fix for someone else. I'm trying to read in the Product to be used in the where clause.

alter proc Proc1
@ProductID int
as
go
select ProductName
from Products
where ProductID = @ProductID

enter image description here

marked as duplicate by Paul White Aug 24 '15 at 2:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

Take out the go after the variable declaration. It is causing SQL server to end the batch which makes your variable declaration go out of scope.

alter proc Proc1
@ProductID int
 as
 select ProductName
 from Products
 where ProductID = @ProductID

Here is some details from Microsoft on what the go keyword/statement does.