Why do I get a "variable is not declared" inside my EXEC statement?

Neil Pike

May 31, 1999

1 Min Read
ITPro Today logo in a gray background | ITPro Today

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.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like