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

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.


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish