Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2002
    Posts
    1,245

    Unanswered: @@ versus @ in T-SQL

    I'm sorry to be ignorant on this point. It seems trivial, but what's the difference between @@ and @ when using variables in T-SQL? I have a developer that always uses @@ for local variables and @ for reference variables (meaning variables declared as parameters for a stored procedure or function).

    Is that purely stylistic? Is it a holdover from some previous version? Or is it a legitimate best practice that I've not seen before?

    My google-shui is weak today; I found nothing when searching.

    Regards,

    hmscott
    Have you hugged your backup today?

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Hidden within the MSDN documentation for Transact-SQL variable names is the secret. One at sign means a variable name, two at signs means a Transact SQL function name disguised as a variable. One of the lovely syntactic hold-overs from the days of SQL 4.x!

    -PatP

  3. #3
    Join Date
    Feb 2004
    Posts
    492
    Second that.

    Also, it seems to me that, when declaring variables, you get to pick the name you want which can include as many as @ you want. I guess sqlserver doesn't really mind. However, you may not want to confuse sql-functions with variables of your own.

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Bottom line: your developer is either misinformed or just plain goofy.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  5. #5
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Quote Originally Posted by blindman
    Bottom line: your developer is either misinformed or just plain goofy.
    I thought that "goofy" was a requirement for being a developer.

    -PatP

  6. #6
    Join Date
    Dec 2002
    Posts
    1,245
    I bow to the masters.

    Thanks to all for your comments.

    And no comment (from me) about developers.

    I have to say that after 10 weeks+ of wrestling with Oracle 10g and ASM, I'm going a bit goofy myself.

    Regards,

    hmscott
    Have you hugged your backup today?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •