Geeks With Blogs

News
The Wrecking Bawl Destructuring query language, one keyword at a time.

One funny (or annoying) thing about T-SQL is that it does not allow you to declare variables (or create temp tables) with the same name in mutually exclusive units of code.  Here's an example of what I mean:

DECLARE @test bit
SET @test = 0

IF (@test = 0)
  BEGIN
    DECLARE @monkey int
  END
ELSE
  BEGIN
    DECLARE @monkey int
  END

If you run that in Query Analyzer you'll get the following message:

Server: Msg 134, Level 15, State 1, Line 11
The variable name '@monkey' has already been declared. Variable names must be unique within a query batch or stored procedure.

 

Posted on Monday, February 26, 2007 11:33 PM all tech stuff , SQL Server | Back to top


Comments on this post: another T-SQL gotcha

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Alex Bransky | Powered by: GeeksWithBlogs.net