Re: Row Order

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Guadala Harry (GMan_at_NoSpam.com)
Date: 11/03/04


Date: Wed, 3 Nov 2004 09:17:00 -0800


<<But the bottom line is that you just can't rely on this to work.>>

Great - this is good to know.
I'll be taking a different approach and pulling the columns from the
underlying tables into the temp table used to do the sorting in the final
SELECT.

Cheers!

"Hugo Kornelis" <hugo@pe_NO_rFact.in_SPAM_fo> wrote in message
news:6jcho0h4431fnnn0lm81lgpj5mogo6ak47@4ax.com...
> On Tue, 2 Nov 2004 16:16:56 -0800, Guadala Harry wrote:
>
> >Thank you Hugo for addressing my actual question...
> >
> >I like your alternative and would normally be doing that. The reason I
don't
> >want to do it is because the columns to sort on are spread amongst 4
> >underlying tables necessitating 3 joins on many columns. While that's not
a
> >big deal by itself I just didn't want all those columns in the temp table
> >because they would be used only for sorting and would not be returned to
the
> >caller. So I thought that IF - and this is the whole reason for the
original
> >post - I could trust the sequence of the inserts into the temp table
(with
> >or without IDENTITY), then I could omit all those columns and have a
cleaner
> >temp table and simpler final SELECT statement.
>
> Hi Guadala,
>
> Understood. But the bottom line is that you just can't rely on this to
> work. There is no way to force SQL Server to insert the rows (annd hand
> out the identity values) in the order you want it, even if you include an
> ORDER BY.
>
> The only workarounds I know are: using a subquery to calculate a rank and
> inserting that (instead of the identity) or using a cursor to insert the
> rows one by one (this WILL of course guarantee that the rows arre inserted
> and the identity values assigned in the desired order). Unfortunately, the
> first option is exponentially slow with large result sets; the second uses
> a trigger, which is generally frowned upon (and for good reason). In your
> case, I'd use the cursor approach if it's a one-time cleanup operation; if
> it's part of a regular, repeating process, I'd try other options first.
>
>
> > the columns to sort on are spread amongst 4
> >underlying tables necessitating 3 joins on many columns. While that's not
a
> >big deal by itself I just didn't want all those columns in the temp table
> >because they would be used only for sorting and would not be returned to
the
> >caller.
>
> I don't understand why you have a problem including more columns in the
> temp table. Okay, they take up some extra space in tempdb, they decrease
> the number oof rows per data page, reducing performance somewhat, but
> unless we're talking big columns (thousands of bytes), I don't think
> you'll notice the performance drop. If I were you' I'd give it a shot and
> test it.
>
> Other that that, you might also consider trying to post your actual table
> structure, sample data and problem description instead of the simplified
> example you posted before. That would allow me (and the other regulars) to
> look at your problem and consider using a different approach to address
> the problem - the simplified post has the down side that we can only help
> you with the solution you already decided upon, even if it's maybe not the
> best possible solution.
>
> Best, Hugo
> --
>
> (Remove _NO_ and _SPAM_ to get my e-mail address)



Relevant Pages

  • Re: Radiative cooling & partly cloudy nights
    ... that in the lowest layers. ... Would you expect the temp at the bottom to rise? ...
    (uk.sci.weather)
  • Re: Best Way to insulate a conical fermenter?
    ... 75.9°F and room temp of 75°F the temp inside the conical is now 73°F. ... colder water is settling to the bottom. ... called my wife and asked her to read digital thermometer i have on top ... I got home and realized my digital thermometer was ...
    (rec.crafts.brewing)
  • Re: Best Way to insulate a conical fermenter?
    ... 75.9°F and room temp of 75°F the temp inside the conical is now 73°F. ... colder water is settling to the bottom. ... It read 71.4°F and the room temp near fermenter is at ...
    (rec.crafts.brewing)
  • Re: Best Way to insulate a conical fermenter?
    ... 75.9°F and room temp of 75°F the temp inside the conical is now 73°F. ... system run for 3 or 4 days and see what temperature it balances at. ... colder water is settling to the bottom. ... colder quicker thus pushing upward in greater volume. ...
    (rec.crafts.brewing)
  • Re: Sorting & Grouping Problem
    ... might be using in a query, the report itself needs the Sorting/Grouping set. ... My report shows Temp, Identifier, and Data in that order from ... Order, Ascending ... In the sorting and Grouping box, if I put Order first, in ascending order, ...
    (microsoft.public.access.reports)