[thelist] ASP/SQL Question

rudy r937 at interlog.com
Fri Sep 14 08:44:12 CDT 2001

> Of course a lot of code has been left out, like checking 
> the ProductType and doing an increment. I do see that 
> code like this would be helpful for lots of applications, like 
> listing offices by state, etc. Am I on the right path here?


in your pseudocode, you have omitted the logic to test
for a change in ProductType

how's this --

   set  currentType="foobar"  /* initial value */
   begin loop
       get next record
       if ProductType <> currentType
           call finishType
           call initializeType
       process current record
   end loop
notice that before processing each record, you just check
whether this record is in the same group as the previous

you pick an initial value for currentType so that it will
not be equal to the ProductType of the first record,
thus triggering finishType and initializeType

the finishType process would do stuff like printing the totals line
for the previous ProductType -- obviously, you check for currentType
being equal to the initial value, and skip if it is

the initializeType process would do stuff like initializing
counters, printing a ProductType heading line, and setting
currentType equal to the value of ProductType for the
current record

this is basic programming for group subtotals that goes
all the way back to punch card systems....

by the way, in cold fusion the current/previous logic is
*built in* to the way the CFOUTPUT tag works when you
use the GROUP parameter... plus, the "get next record"
is transparent, i.e. it is inherent in the CFOUTPUT tag itself

so in cold fusion, it would look something like this --

   <cfset firsttime="yes">
   <cfoutput  query="queryname"  group="ProductType">
      <cfif firsttime is "yes">
         <cfset firsttime="no">
           finish previous group (print subtotals, etc.)
      do other initialization for new group
           print details for each record

note you still need something to stop printing group
subtotals ahead of the first group

>As an aside, Rudy, why is data shaping evil?

for a simple one-level parent-child relationship,
it is trivial (as mentioned in the 4guys article)

for more complex relationships, it is horrendously
difficult to understand

furthermore, it is proprietary (this is the sense in which
i used the "spawn of satan" description -- microsoft
being known as the evil empire)

yes, i am aware that there are plenty of people who
concede that microsoft, by its dominance of markets,
does not, by definition, produce proprietary code

there also seems, on the surface, to be little harm
in using a proprietary asp solution if you're already 
committed to using asp itself

and i'm not knocking the performance of a data shaping
solution, i have no idea how it would compare to the
performance of a different solution

knowing microsoft, the performance would actually be
pretty good

or maybe not

but basically, i was thinking of the complexity of the 
data shaping solution

here you have asp touted as the entry language for
people just coming in to the world of databases, and
all of a sudden you layer this entirely different logical
structure on top of what is already unnecessarily
complicated programming to access query results

i have seen people run a query, process the result set
in a loop, and for every record, run another query against
a different table -- perhaps because they had never heard 
of a join, perhaps because they theought they were using 
a cursor, perhaps because asp makes this possible without 
running up the performance overhead and turnaround time...

of course, the answer to sluggish performance has always
been Install Bigger Machine (the initials show that this was
a wildly popular strategy even before microsoft)

when the answer to a performance problem is to throw
more hardware at it, you have to wonder who's going to
benefit from the license fees for all the additional server
software that will be required...

i guess i should stop, i seem to be ranting...


More information about the thelist mailing list