Daniel Wilson
asked on
SQL Server 2000 - "must declare variable '@ID'" after USE statement
I have a variable scoping problem. The following (simplified) script generates 2 "Must declare the variable" errors.
What do I need to do to overcome the scope issue and use the variable against both DB's?
Thanks!
Msg 137, Level 15, State 2, Line 1
Must declare the variable '@ID'.
Msg 137, Level 15, State 2, Line 3
Must declare the variable '@ID'.
What do I need to do to overcome the scope issue and use the variable against both DB's?
Thanks!
Msg 137, Level 15, State 2, Line 1
Must declare the variable '@ID'.
Msg 137, Level 15, State 2, Line 3
Must declare the variable '@ID'.
begin tran
Declare @ID int
Set @ID = 5
use Database1
go
Select @ID
go
use Database2
go
Select @ID
rollback tran
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER