The Wrecking Bawl

Destructuring query language, one keyword at a time.


News


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.

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Comments

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: