|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Friday, February 04, 2011 7:20 AM
Points: 977,
Visits: 1,499
|
|
Ya got me.
Tom Garth Vertical Solutions
"There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." -- Will Rogers
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Friday, December 07, 2012 8:25 AM
Points: 540,
Visits: 245
|
|
| This was a great instructional puzzle. I appreciate the corporate knowledge this forum represents. Thanks.
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Yesterday @ 2:18 AM
Points: 932,
Visits: 229
|
|
dun (11/26/2009) This was a great instructional puzzle. I appreciate the corporate knowledge this forum represents. Thanks. Glad you enjoyed it This example actually came to mind because of the amount of times I fell over things like this when I was doing serious T-SQL programming for the first time a couple of years ago, when trying to improve and modify the thousands of lines of code left for us to ... try to deal with ... by an (SEI Level 5 - ha!) outsourcing company who wrote our then brand-new system.
-- Kev
------------------------------- Oh no!
|
|
|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Tuesday, April 02, 2013 3:48 AM
Points: 660,
Visits: 557
|
|
Nice question.
Along the same lines of "no rows returned, do nothing", I have a feeling that it may be a case of "400 rows returned, assign 400 values to the same variable" so you are just left with the last one it assigned.
My question is, if you're not doing anything with that variable (i.e. "select @val = col from tab" rather than "select @val = @val + col from tab"), does the optimizer spot this and skip all the variable assignments and just do the last one, or are you inadvertantly creating overhead by assigning every single value that you will never see?
-------- I love deadlines. I like the whooshing sound they make as they fly by. -Douglas Adams
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Today @ 12:56 AM
Points: 1,972,
Visits: 1,822
|
|
Rob Goddard (11/27/2009)
does the optimizer spot this and skip all the variable assignments and just do the last one? All the variable assignments are done.
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Yesterday @ 2:18 AM
Points: 932,
Visits: 229
|
|
Carlo Romagnano (11/27/2009)
Rob Goddard (11/27/2009)
does the optimizer spot this and skip all the variable assignments and just do the last one?All the variable assignments are done. I spose this makes sense given the quick method of building a csv from a column i.e. it's clearly possibly that a single variable declaration from a select which returns multiple rows can make use of information from every row. For the optimiser to spot that it was being assigned to a single variable AND that it would only require data from one row to create the necessary value, it would have to be an exceedingly clever piece of logic.
-- Kev
------------------------------- Oh no!
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Monday, October 22, 2012 7:08 AM
Points: 232,
Visits: 112
|
|
nice one! :) its strange!
Thanks,
Ashka Modi Software Engineer || credEcard Technologies (india) Pvt. Ltd.
|
|
|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Friday, January 11, 2013 12:41 PM
Points: 621,
Visits: 297
|
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 3:12 AM
Points: 7,106,
Visits: 7,171
|
|
It would have been a good idea to reference http://msdn.microsoft.com/en-us/library/ms187330.aspx as well as the coalesce page, because people thinking that if no value is returned the value is set to null is a pretty common error. I must have explained a few dozen times over the years that
select @a = iValue from @vals where iKey <> iValue and
set @a = (select iValue from @vals where iKey <> iValue) behave completely differently when the filter passes no rows.
Tom Que conclure à la fin de tous mes longs propos? C'est que les préjugés sont la raison des sots. (Voltaire, 1756)
|
|
|
|