Consulting

Results 1 to 9 of 9

Thread: What's with the "@" symbol?

  1. #1
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location

    What's with the "@" symbol?

    In SQL Server:

    I don't know where to find any documentation on what the "@" symbol means and why it is used. I've done different kinds of advanced google searches for this (e.g. "inurl:forum "@.symbol") and I get squat. I've seen it used plenty of times, but nobody explains it...

    Can anybody explain what this is and what it does and how to use it? Or maybe a link to a site that explains it?




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  2. #2
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    Joseph,

    Can you explain the context? Generally, user variable names in a SQL batch are preceded by an @:

    DECLARE @MyVariable varchar(100)
    SET @MyVariable = 'Joseph is pretty cool!'
    Certain system state values are preceded by @@. For example, to see what is currently set as the first weekday of the week:

    SELECT @@DATEFIRST AS FirstDayOfWeek
    If that's not what you mean, then...
    Regards,

    Patrick

    I wept for myself because I had no PivotTable.

    Then I met a man who had no AutoFilter.

    Microsoft MVP for Excel, 2007 & 2008

  3. #3
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Patrick,

    First, thank you for the response. It has given some insight towards finding my answer.

    And I'm sorry, but I truly didn't know what context it held! The only thing I could think of was the variable thing (since I've seen it that way one time), but I didn't even know if that was right.

    I have also seen it without being declared; like in the middle of the query:

    SELECT col1 FROM @Table1 WHERE ...

    Or something the like. This made me think that the sql engine would prompt the user for some kind of input (like an input box saying "What table do you want to grab data from?").

    The most frustrating part is that I can't seem to do a search for this symbol in any context with SQL. And also, I'm not sure if this "@" character is part of T-SQL's extended functionality, or considered just SQL. Regardless, I've tried searching for both and had no luck.

    And for some insane reason, I thought that maybe it's some special character for searches...like a wildcard or something. Man, I even tried "\@" to maybe escape that character!


    I guess I just don't like the fact that I can't find information on this "secretly special" '@' symbol anywhere.

    Thanks again for the input Patrick If you have any links to more queries like that, I'm well interested!




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  4. #4
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    Joseph,

    Based on the syntax you posted above, I would guess that @Table1 is a table variable: T-SQL allows you to define variables of data type table. These table variables generally behave the same way "real" tables behave. The big exception, of course, is that they exist only in RAM, and once the SQL code stops executing, they evaporate.

    I rarely do this; typically, whenever a table variable would useful, I will just create a temporary table instead. I'm not saying my way is better--it's just how I learned how to do things, and I have not yet seen any good reason to break the habit.
    Regards,

    Patrick

    I wept for myself because I had no PivotTable.

    Then I met a man who had no AutoFilter.

    Microsoft MVP for Excel, 2007 & 2008

  5. #5
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Patrick,

    Ah. I see. That's an interesting thought - to use RAM for a temporary table. I would think you would want to keep the data a little longer than when the query stopped. Unless that query ended up giving back some kind of calculated answer for ya.

    So I think I'll look towards T-SQL for some more info on this. That will narrow down my search pretty well.

    Thanks again Patrick. If I find some interesting links about this, I'll post them here.




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  6. #6
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location

  7. #7
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Thanks Stan, I'll take a look into it.




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  8. #8
    VBAX Master XLGibbs's Avatar
    Joined
    Jan 2006
    Location
    state of confusion, but vacation in denial
    Posts
    1,315
    Location
    @ can be used as an indicator for session related objects in query analyzer or stored procedure, and yes, can be used to declare a table variable...
    If you have posted the same question at multiple forums, please read this IMPORTANT INFO.

    Please use the thread tools to mark your thread Solved


    Please review the Knowledge Base
    for samples and solutions , or to submit your own!




  9. #9
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Thanks for the info Gibbs and Stan. I've also found out that the '@@' means a globally defined variable. Here is the site for more info.




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

Posting Permissions

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