how to tell when @@ is a global variable vs function?

Hello, @@ has been confusing me while I learn t-sql. How do I tell when @@ is used as a global variable (my tsql2005 books) vs how do I tell when its being used for a function in 2008 or 2012 tsql? 

Thanks for any examples or tips!! :)

currently reviewing:

https://msdn.microsoft.com/en-us/library/ms187953.aspx

May 24th, 2015 10:47pm

I can't find a similar @@ function explanation msdn article for review.
Free Windows Admin Tool Kit Click here and download it now
May 24th, 2015 11:36pm

are you able to help shed more lite on this from msdn or provide examples?

"The names of some Transact-SQL system functions begin with two at signs (@@). Although in earlier versions of Microsoft SQL Server, the @@functions are referred to as global variables, they are not variables and do not have the same behaviors as variables. The @@functions are system functions, and their syntax usage follows the rules for functions."

May 25th, 2015 12:10am

It says @@ represents system functions and they were earlier called as global variables. There are lot of examples like @@DATEFIRST,@@ERROR,@@IDENTITY etc

As specified they are all system functions and follow rules for functions 

Free Windows Admin Tool Kit Click here and download it now
May 25th, 2015 1:03am

If they are listed in Books Online as functions, then the things starting with @@ are functions (called "global variables" in SQL 6.5 and earlier). If they are not, the are just plain local variables. In practice, the only @@-functions you use are @@spid, @@trancount, @@nestlevel and maybe somemore. Many of them are esoteric.

May 25th, 2015 2:54am

If they are listed in Books Online as functions, then the things starting with @@ are functions (called "global variables" in SQL 6.5 and earlier). If they are not, the are just plain local variables. In practice, the only @@-functions you use are @@spid, @@trancount, @@nestlevel and maybe somemore. Many of them are esoteric.

A few more that you could see are @@version, @@servername, @@rowcount, @@identity and @@error.

Free Windows Admin Tool Kit Click here and download it now
May 25th, 2015 4:24am

thanks guys, any articles on traditional functions that dont use @@ for comparison? example I am from a powershell background which is similar to vb/c++ where you would create a function in your script then reference it as a keyword/function to execute the function. 

also any examples of @@ in use?

May 25th, 2015 7:17pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics