March 22, 2010 at 1:12 pm
from BOL:
Declaring a Transact-SQL Variable
The DECLARE statement initializes a Transact-SQL variable by:
* Assigning a name. The name must have a single @ as the first character.
...
Nothing wrong with that, except maybe "a single @ as the first character". It is hard to imagine to squeeze more single anything as the first character.
But, did you know that the following will compile just fine and it'll work as well?
declare @ datetime, @@ int, @@@ varchar(16),@$ int, @$#$@@ int
select @=getdate(),
@@=1,
@@@='funny variable',
@$=2,
@$#$@@=3
select @,@@,@@@,@$,@$#$@@
As long as the first character is a 'single' @, any combo of {'$','#'} will do.
I'm saving my alphanums for later 😉
March 22, 2010 at 1:18 pm
deepforest (3/22/2010)
But, did you know that the following will compile just fine and it'll work as well?
Why, yes. 😛
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
March 22, 2010 at 1:18 pm
...did you know that the following will compile just fine and it'll work as well?...
Yes
March 22, 2010 at 1:26 pm
Yes. Nice tidbit though to point out.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
March 22, 2010 at 2:42 pm
Yes! There was a really funny Question of the Day about names.
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
March 22, 2010 at 3:40 pm
March 22, 2010 at 3:43 pm
The Dixie Flatline (3/22/2010)
Yes! There was a really funny Question of the Day about names.
Which one was that? I don't recall it.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
March 22, 2010 at 3:53 pm
Jason, I just searched back through T-SQL QotDs looking for the string "Name" and couldn't find it. 🙁
I distinctly remember some of the odd things from it though. For example a blank is a valid table name.
select top 10 name
into [ ]
from sys.databases
select * from [ ]
drop table [ ]
Try putting a period, an apostrophe, etc. within the brackets as a table name. They all work.
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
March 22, 2010 at 5:15 pm
The Dixie Flatline (3/22/2010)
Jason, I just searched back through T-SQL QotDs looking for the string "Name" and couldn't find it. 🙁I distinctly remember some of the odd things from it though. For example a blank is a valid table name.
select top 10 name
into [ ]
from sys.databases
select * from [ ]
drop table [ ]
Yup - I have seen the odditites such as that. If importing from excel, those happen frequently.:-D
Try putting a period, an apostrophe, etc. within the brackets as a table name. They all work.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
March 23, 2010 at 3:13 am
Note that variable names @, @@ or names starting with @@ are deprecated in SQL 2008. See http://msdn.microsoft.com/en-us/library/ms143729.aspx:
Do not use @ or @@ or names that begin with @@ as identifiers.
Peter
March 23, 2010 at 7:01 am
Garadin (3/22/2010)
Fine, I'll bite. I didn't!
somebody is kranky today...
March 23, 2010 at 7:27 am
Heh, no, you mistook me. I wasn't cranky at all. I was joking around with them all being buzzkills with the 'already knowing it' and letting you know that I didn't, and thus this post was educational to someone at least :hehe:. I think my wording could have been better though.
March 23, 2010 at 7:49 am
just kidding, just kidding..;-)
March 23, 2010 at 10:37 am
Garadin (3/23/2010)
Heh, no, you mistook me. I wasn't cranky at all. I was joking around with them all being buzzkills with the 'already knowing it' and letting you know that I didn't, and thus this post was educational to someone at least :hehe:. I think my wording could have been better though.
Nope - didn't take it as cranky and took the post just as you explained.
Just trying to be a buzzkill still 😉
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
March 24, 2010 at 6:57 am
deepforest (3/22/2010)
But, did you know...
Yes.
One of my favourite QODs was the one that executed a procedure named GO.
Viewing 15 posts - 1 through 15 (of 33 total)
You must be logged in to reply to this topic. Login to reply