SQL Server Performance

What are Local Variables?

Discussion in 'General Developer Questions' started by Jaybee from his castle, Oct 7, 2003.

  1. Hi guys

    I've done truckloads of Admin, but I'm pretty light on procedures/scripts, I've only ever had to look at a few scripts since 99. I picked up a book on T-SQL and got through the first couple of chapters.

    Now, I can't quite fathom what Local variables are, how/why they're used, benefits etc.

    Can anyone give me an explanation and ideally some examples too?


    Thanks,


    JB.

    France.

    The finest wines.

    The tastiest cuisine.

    The most delicious women.
  2. Argyle New Member

    Example of global variables are:
    @@VERSION
    @@ERROR
    @@IDENTITY
    @@TRANCOUNT
    @@ROWCOUNT

    Example: SELECT @@VERSION

    You call variables begining with @@ for global variables (they are basically functions returning values). These are system wide variables that can be used from any script. Local variables are variables defined in for example a stored procedure that you define yourself. Like @myID or something, using only one @.

    /Argyle
  3. quote:Originally posted by Argyle

    Example of global variables are:
    @@VERSION
    @@ERROR
    @@IDENTITY
    @@TRANCOUNT
    @@ROWCOUNT

    Example: SELECT @@VERSION

    You call variables begining with @@ for global variables (they are basically functions returning values). These are system wide variables that can be used from any script. Local variables are variables defined in for example a stored procedure that you define yourself. Like @myID or something, using only one @.

    /Argyle


    Thanks! I've seen (and used) @@version before, I guess I'm more confused by Local Variables, what you do with them, why etc.

    JB.

    France.

    The finest wines.

    The tastiest cuisine.

    The most delicious women.
  4. Luis Martin Moderator

    I suggest see BOl there is a lot of examples using global variables.



    Luis Martin

    ...Thus mathematics may be defined as the subject in which we never know what we are talking about, nor whether what we are saying is true.
    Bertrand Russell
  5. Argyle New Member

    I see now you replaced the word global with local in your post <img src='/community/emoticons/emotion-1.gif' alt=':)' /><br /><br />To see some examples of local variables (with one @) used in scripts check the scripts forum:<br /<a target="_blank" href=http://www.sql-server-performance.com/forum/forum.asp?FORUM_ID=11>http://www.sql-server-performance.com/forum/forum.asp?FORUM_ID=11</a><br /><br />Example:<br /<a target="_blank" href=http://www.sql-server-performance.com/forum/topic.asp?TOPIC_ID=298>http://www.sql-server-performance.com/forum/topic.asp?TOPIC_ID=298</a><br /><br />/Argyle
  6. satya Moderator

    Also check FUNCTIONS topic under books online for detailed information.

    _________
    Satya SKJ
    Moderator
    SQL-Server-Performance.Com

Share This Page