Sunday, March 25, 2012

@@ 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,

hmscottHidden within the MSDN documentation (http://msdn2.microsoft.com/en-us/library/ms187953.aspx) 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|||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.|||Bottom line: your developer is either misinformed or just plain goofy.|||Bottom line: your developer is either misinformed or just plain goofy.I thought that "goofy" was a requirement for being a developer.

-PatP|||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,

hmscottsql

No comments:

Post a Comment