Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 Incremental additions Rate Topic Display Mode Topic Options
Author
 Message
 Posted Friday, October 29, 2010 8:53 AM
 Mr or Mrs. 500 Group: General Forum Members Last Login: Monday, May 21, 2012 3:13 PM Points: 516, Visits: 1,563
 I hate to admit it, but I got distracted by the fact that the select contained "@a A". Thinking that this was too easy of a question made me guess that the A was some obscure way of applying an absolute value function, hence I was the one person that chose "0,21" for an answer. I hope it comes from infrequent selection of variables to display them and not from turning 60 this year.Steve
Post #1013127
 Posted Friday, October 29, 2010 9:39 AM
 Forum Newbie Group: General Forum Members Last Login: Tuesday, December 03, 2013 8:46 AM Points: 6, Visits: 111
 Yes, I agree. The explanation is incorrect.To further illustrate what is happening here, try substituting =+ with =-My interpretation is that you are applying a positive modifier to a negative value,which obviously results in a negative return. If you apply a negative modifier to a negative number, the result is positive.` select @a =- @b `will return +21 when b is -21
Post #1013170
 Posted Friday, October 29, 2010 9:45 AM
 SSC Journeyman Group: General Forum Members Last Login: Thursday, February 17, 2011 9:34 AM Points: 75, Visits: 23
 Correct me if I'm wrong. It's the spacing that is throwing most people off.@a =+ @b is the same as @a = (+1) * @bif i were to write this in my code I would format it as@a = +@bbut i wouldn't do that since +1 times any number yields that same numberNote that they mention a pre-increment operator but they mean a Compound Operator. Also note Compound Operators are only availabe in SQL 2008. Writing @a += @b would throw a syntex error in earlier version.
Post #1013175
 Posted Friday, October 29, 2010 10:05 AM
 SSCrazy Group: General Forum Members Last Login: Thursday, November 07, 2013 10:01 AM Points: 2,163, Visits: 2,181
 I too wonder if the intent was to make you think it was the compound "+=" operator that was added in SQL Server 2008. Then the results would be 0, -21.But since there was no mention of SQL Server 2008 I assumed it wasn't.
Post #1013193
 Posted Friday, October 29, 2010 11:39 AM
 SSCommitted Group: General Forum Members Last Login: Tuesday, December 03, 2013 5:28 PM Points: 1,676, Visits: 1,728
 Oh well, I lost a precious point on this one. The statement in questionselect @a =+ @blooked so ridiculous that it made me think that there were 2 possibilities: - either it was the author's intention to actually write it as is, perhaps to show how difficult it can be to debug the errors based on misplacing the order of typed characters- it was a simple typo, and the += was intendedUnfortunately, I chose the second option and thus answered the question incorrectly. I don't consider it a bad question, but cannot say that I learned something from it either, because in reality, nobody can actually benefit from ever typing something like select @a =+ @bwhen select @a = @b does the trick.Oleg
Post #1013245
 Posted Friday, October 29, 2010 12:43 PM
 SSCrazy Group: General Forum Members Last Login: Yesterday @ 7:06 AM Points: 2,812, Visits: 837
 Oleg Netchaev (10/29/2010)Oh well, I lost a precious point on this one. The statement in questionselect @a =+ @blooked so ridiculous that it made me think that there were 2 possibilities: - either it was the author's intention to actually write it as is, perhaps to show how difficult it can be to debug the errors based on misplacing the order of typed characters- it was a simple typo, and the += was intendedUnfortunately, I chose the second option and thus answered the question incorrectly. I don't consider it a bad question, but cannot say that I learned something from it either, because in reality, nobody can actually benefit from ever typing something like select @a =+ @bwhen select @a = @b does the trick.OlegNo, but you can benefit from knowing that it's an easy to make mistake, and that SQL Server won't alert you to the problem. Just because you're right doesn't mean everybody else is wrong.
Post #1013280
 Posted Saturday, October 30, 2010 5:52 AM
 SSCertifiable Group: General Forum Members Last Login: Today @ 3:35 AM Points: 7,934, Visits: 8,351
 Not only is the explanation wrong, as several people have pointed out, it is also uses somewhat outdated terminology and is maybe confused about which version of SQL it refers to. The term "positive operator" was used in BoL for SQL 2000, but from SQL 2005 on that term is not used , the operator is called "unary plus" (presumably because MS relised that the term "positive operator" would be likely to confuse people when applied to a copy or no-op operator); but the question is clearly trying to trap people into mistaking =+ for += (why else would the first answer option be exactly what would be seen if the query had had += instead of =+), and += first appeared in SQL 2008, not in SQL 2000. Tom'S iomadh doigh a th’ air cu a mharbhadh gun a thachdadh le ìme
Post #1013444
 Posted Sunday, October 31, 2010 6:10 PM
 SSChasing Mays Group: General Forum Members Last Login: Sunday, November 17, 2013 11:53 AM Points: 623, Visits: 237
 Good Question. and very good follow up threads by some members. it clears some lack of answer explanations.
Post #1013650
 Posted Sunday, October 31, 2010 9:46 PM
 Forum Newbie Group: General Forum Members Last Login: Tuesday, October 15, 2013 10:52 PM Points: 3, Visits: 17
 da-zero (10/29/2010)[quote]Iulian -207023 (10/29/2010) It still remains unknown to me why SQL Server ignores the + in =+ instead of giving a syntax error.If I understand correctly, it is not actually a syntax error. As someone else stated, the plus is a unary operator: @a = (+@b). To put in perspective, if the statement was @a =- @b, then @a now becomes 21, essentially @a = - (-21).Hope that helps.EDIT: Sorry, didn't realise there were more posts that have already explained this. Ignore at your own will.
Post #1013663
 Posted Tuesday, November 02, 2010 2:28 PM
 SSCoach Group: General Forum Members Last Login: Yesterday @ 10:17 PM Points: 19,460, Visits: 13,050
 Nice question Jason AKA CirqueDeSQLeilI have given a name to my pain...MCM SQL Server 2008SQL RNNRPosting Performance Based Questions - Gail ShawPosting Data Etiquette - Jeff ModenHidden RBAR - Jeff ModenVLFs and the Tran Log - Kimberly Tripp
Post #1014890

 Permissions