Ah! Well, I think if you're trying to do it in straight-up SQL with very little Perl, it'll be quite tricky. In order to get the order-preservation you need, I'm pretty sure you'd have to create a temporary table with the additional "counter" column I mentioned above (not sure how you would do this in DB2 but suspect there is a function to get that); also, with a temporary table you could update all NULL values to 0, sidestepping that problem as well. Since you're in DB2 you could automate the whole shebang with SPUFI. Or if you have QMF around you might be able to do everything within a FORM.

But we're straying pretty far from Perl now and I really do think it'll be easier to dump the table into Perl's control and do all of your stuff there. It is the Practical Perfect Extraction and Reporting Language after all :). SQL is all well and good when you're working with more than one table but if you're trying to do fancy stuff within a result set it's almost always easier to program it.


In reply to Re: Re: Considerations on ordering by cebrown
in thread Sorting by johnirl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.