A. This is because a variable is local to a batch of SQL - normally batches are split up with GO statements. However an EXEC is a separate batch and so it cannot see any local variables already created.

You must put the variable declarations you need inside the EXEC statement.