USE DATABASE_A
GO
DECLARE @Action_ID AS UNIQUEIDENTIFIER = (SELECT Action_ID FROM Actions WHERE CodeNumber = 'VCT-XXX-000001');
USE DATABASE_B
GO
DECLARE @Property_ID AS INT = (SELECT Property_ID FROM [Properties] WHERE Action_ID = Action_ID);
Above am declaring and setting variable @Action_ID
with a query that selectes from table "Actions" which is in database DATABASE_A
I want to use @Action_ID
in a query that will be executed against database DATABASE_B but that throws an error that says
"Must declare the scalar variable "@Action_ID".
How can i use variable @Action_ID
in queries that will be executed against database DATABASE_B