December 4, 2013 at 10:13 pm
Comments posted to this topic are about the item Declare @local variable
December 4, 2013 at 10:24 pm
easy one for the guys who has past experience in 2005
December 4, 2013 at 10:46 pm
i almost clicked on "YES".
Thanks for sharing
December 5, 2013 at 1:03 am
This was removed by the editor as SPAM
December 5, 2013 at 1:19 am
Mr. Kapsicum (12/4/2013)
easy one for the guys who has past experience in 2005
And those with current experience of 2005:-)
December 5, 2013 at 1:35 am
Easy (maybe too easy?).
December 5, 2013 at 1:43 am
Thanks for the easy one!
December 5, 2013 at 2:51 am
Love the "maybe" option! made me think twice before answering
December 5, 2013 at 6:09 am
paul s-306273 (12/5/2013)
Easy (maybe too easy?).
Well I thought I would give an easy one to "make up" for the "Order My Data" question I submitted. But you would be surprised how many developers get this one wrong. :w00t:
December 5, 2013 at 6:44 am
The first SQL server version I worked with was 2000. I got into the habit of declaring and setting in two statements and I still do that today. I forgot you can declare and set in one statement. :crazy:
Tom
December 5, 2013 at 7:31 am
December 5, 2013 at 8:17 am
I had to do some research on this one because we jumped from 2000 to 2008. Like many others, I have always set my variables in separate SET statements anyway. It wasn't until I saw someone else's code on a 2008 instance a couple years ago that I saw a value set in the declaration. Thanks for the question Steve!
December 5, 2013 at 8:30 am
Carlo Romagnano (12/5/2013)
Starting from sqlserver2008, you can declare and set a variable in one statement,but you can NOT initialize a second variable with another inside the same declaration.
declare @a varchar= 'A'
,@b varchar= @a
You should have two DECLARE
declare @a varchar= 'A'
Absolutely true Carlo. Simple reason, query "parser"\optimizer has no idea what @a is. So you are setting it before declaring it (backwards). This is seen in many (if not all) programming languages.
Thanks
December 5, 2013 at 8:39 am
Ahh, this brought back bad memories of all the extra typing required to declare and set variables in separate statements. I still say a silent "hallelujah" every time I declare and set a variable in the same statement.
Jason Wolfkill
December 5, 2013 at 11:37 am
I got it right but only by guessing if the question was to be answered or the description.
The problem is that, as written, the question and the description have 2 different answers.
In SQL Server 2005, is the code segment (a local variable in a stored procedure) below allowed?
The question "In SQL Server 2005, is the code segment below allowed?" has one answer.
The description "(a local variable in a stored procedure)" has a different answer.
In order for the description to match the question it would have to read "(a local variable, declared and set in one line, in a stored procedure)".
I don't see too many complaints though so maybe I'm the only one who thought there could be a trick in the wording.
Thanks for the QotD!
Viewing 15 posts - 1 through 15 (of 24 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy