x

Sql Server - Difference between @id and @@id

What is the difference between the following declarations:

DECLARE @id bigint and DECLARE @@id bigint

more ▼

asked May 26, 2010 at 10:59 AM in Default

avatar image

Fayu
35 4 4 8

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

There is no difference. The rules for variables state that they start with an '@' character and follow the rules for identifiers.

Since '@' is a valid identifier character, you can have as many as you like at the start of your variable name. However, if you match a system function which has the same name as your variable, then the query will not compile.

more ▼

answered May 26, 2010 at 11:10 AM

avatar image

Matt Whitfield ♦♦
29.5k 62 66 88

(comments are locked)
10|1200 characters needed characters left

In previous versions of SQL Server @ described a local variable and @@ describe a global variable. Now (SQL 2008) @@ is used for a function name so @@ shouldnt be used as a parameter name.

Books OnLine ref http://msdn.microsoft.com/en-us/library/ms187953.aspx

more ▼

answered May 26, 2010 at 11:08 AM

avatar image

Fatherjack ♦♦
43.7k 79 98 117

Yep - what that is saying is that the @@ system functions used to be called 'global variables' - but they weren't actually variables at all...

May 26, 2010 at 12:26 PM Matt Whitfield ♦♦
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x992
x408

asked: May 26, 2010 at 10:59 AM

Seen: 6353 times

Last Updated: May 26, 2010 at 10:59 AM

Copyright 2016 Redgate Software. Privacy Policy