Question

Parsing and controlling display getrows Array data....

Asked by: joejenkinsjax

Hello!

I'm pulling a large quantity of data from a database using .getrows but I need to be able to split that data and display it according to category:

My array data, pipe (|) delimited, looks like this:

6087|195|25|000.96|COMMODITY INVENTORY|CAN|APPLE SLICES, Commodity 6/#10 Cans|

The 3rd, 4th and 5th fields are information I need for the headers of the category lists that a grouping of items will need to be separated by.

Here's the SQL query to gather the data:
sql_show = "SELECT DISTINCT ITEM.Supplier_Item_Number, ITEM_CATEGORY.Category_ID, ITEM_CATEGORY.Account_ID, ITEM_CATEGORY.Minor_Description, ITEM_UNIT.Item_Unit_Description, ITEM.Item_Description FROM (ITEM_CATEGORY INNER JOIN (ITEM_UNIT INNER JOIN ITEM ON ITEM_UNIT.Item_Unit_Id = ITEM.Item_Inventory_Unit) ON ITEM_CATEGORY.Category_ID = ITEM.Category) ORDER BY ITEM_CATEGORY.Account_ID, ITEM_CATEGORY.Minor_Description, ITEM.Item_Description"

I need to be able to parse the data by the 3rd column (in this case the 25) and get only the items from Category 25, build a header and display them something like this:

000.96 - COMMODITY INVENTORY (Category 25)
Item No. Unit    Description
========================================
6087     CAN     APPLE SLICES, Commodity 6/#10 Cans  
6088     CAN     APPLESAUCE, Commodity 6/#10 Cans  
6655     LBS      BEAN GREEN FROZEN, Commodity 30#  

204.50 - COLD BEV CAN&BOTTLE  (Category 26)
========================================
Item No.  Unit         Description
PEP100     CASE     12/11.5 OZ BOTTLES JUICE -DOLE  
PEP101     CASE     12/15.2 OZ BOTTLES JUICE -DOLE  
PEP102     CASE     24/12 OZ BOTTLE AQUAFINA WATER  

This needs to continue on displaying all items under that category, etc.  

Any thoughts on the best implementation for this?

Joe

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-09-05 at 12:21:44ID21978822
Tags

getrows

Topic

Active Server Pages (ASP)

Participating Experts
1
Points
500
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. par file
    Waht is a file with .par used for and what does this extension mean? Can I list the parameters for import in a .par file and use this file in imp, like imp file=filename.par Please suggest.
  2. par io err laserjet 4 plus
    Every time I start my computer my old laserjet 4 plus comes up with an error message on the control panel "err par io" the work around is to cycle power on the printer after the computer is loaded. This problem started when I got a new computer. I have tried chan...
  3. PAR Protocol
    How has the PAR Protocol been extended for use in the Internet?
  4. Converting from PERL to Executable using PAR
    I have a PERL script that begins with the following: use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; When I convert my PERL script to an executable using pp -o file.exe file.pl, there is no problem. But, when I run file.exe I receive the following pop-...
  5. What does the /par in a .bat file mean?
    I am learning to do batch files, and came across this /par in my .bat file. I dont know really how it got there, as I was just manually creating the batch. I did just install easy batch creator, but I didnt use that prog. Anyway here is the code that I have in my batch, but ...
  6. Importing Error --Using Par file.
    Hi experts. we are using Oracle 10g database. using DATA PUMP i exported data. I have exported dump file & target data base in place. I just need to import only data to target data base, tables which I am importing have constraints defined.( I don't want to disable the...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: fritz_the_blankPosted on 2006-09-05 at 12:32:37ID: 17458342

I can help you with this, but we have to do it a step at a time as I can't test here.

First step:

arrRows = objRS.GetRows()
objRS.Close
set objRS = Nothing


Response.Write("<Table Border=1 cellpadding=2 cellspacing=2>" & VBCrLf)
for i=0 to UBound(arrRows,1)
      Response.Write("<TR>" & VBCrLf)
      for j=0 to UBound(arrRows,2)
            Response.Write("<TD>" & arrRows(i,j) & "</TD>")
      next
      Response.Write("</TR>" & VBCrLf)
next
Response.Write("</Table>")

 

by: joejenkinsjaxPosted on 2006-09-05 at 12:43:56ID: 17458419

OK, that output is like this:
Starting Data like this:
6087|195|25|000.96|COMMODITY INVENTORY|CAN|APPLE SLICES, Commodity 6/#10 Cans|

Your table output:
|---------------------|
|6087                   |
|---------------------|
|195                     |
|---------------------|
|25                       |
|---------------------|
|000.96                 |
|---------------------|
|Commodity          |
|Inventory             |
|---------------------|
|CAN                    |
|---------------------|
|APPLE SLICES,     |
|Commodity 6/#10|
|Cans                   |
|---------------------|

This continues all the way across the screen to the right.

Joe

 

by: fritz_the_blankPosted on 2006-09-05 at 13:16:53ID: 17458666

Okay, good. Now we need to split the string:

Response.Write("<Table Border=1 cellpadding=2 cellspacing=2>" & VBCrLf)
for i=0 to UBound(arrRows,1)
      Response.Write("<TR>" & VBCrLf)
      for j=0 to UBound(arrRows,2)
            arrFields = Split(arrRows(i,j),"|")
            Response.write("<td>" & arrFields(2) & "</td>"
            Response.write("<td>" & arrFields(3) & "</td>"
            Response.write("<td>" & arrFields(3) & "</td>"
      next
      Response.Write("</TR>" & VBCrLf)
next
Response.Write("</Table>")

FtB

 

by: joejenkinsjaxPosted on 2006-09-05 at 14:02:08ID: 17459035

I'm getting:
Microsoft VBScript runtime error '800a0009'
Subscript out of range: '[number: 2]'

/getrows/getrows2.asp, line 27
 

Line 27: Response.write("<td>" & arrFields(2) & "</td>")

Joe

 

by: joejenkinsjaxPosted on 2006-09-05 at 14:09:37ID: 17459091

I wasn't very clear in the initial posting that the Pipe (|) is not part of the database.  When I was displaying the data in rows I put the | as part of the response.write to be able to visually differentiate between columns.  The actual output of a line without it looks like this:

608719525000.96COMMODITY INVENTORYCANAPPLE SLICES, Commodity 6/#10 Cans

Joe

 

by: fritz_the_blankPosted on 2006-09-05 at 15:18:50ID: 17459505

I am not sure that I follow. Are you saying that you have seven fields and what you want to do is to group them by the 3rd, 4th, and 5th?

If so, then you need to add the GROUP BY clause in your SQL select.

FtB

 

by: joejenkinsjaxPosted on 2006-09-05 at 15:30:07ID: 17459541

You are correct in that they get grouped by the 3rd, 4th amd 5th elements.  They really only get grouped by the 3rd element (category ID in this case, ie "25, 26, 27, etc").  That's where I need to split them so that I can generate a header for the table that contains only that category (Element #3) and the header information (#'s 4 & 5), display all those results and then generate another header for the next one.  That needs to continue on until there are no more categories (element #3)

Does that make a little more sense?

I was doing this using a recordset.filter method and I would just .filter using a "categoryID = 25" or whatever one I was on.  This works well, except that this database is steadily kicking out over 600+ rows of items now with a steady 150 users and it's just too much data to be parsing in that inefficient manner.  By using getrows, it's significantly faster, the databases close much quicker and pages are served faster.  

Follow me?

jj

 

by: fritz_the_blankPosted on 2006-09-05 at 15:36:24ID: 17459570

Not exactly, but I do something like this:

intCategory= ""
do while not objRS.EOF
     if objRS("intCategory") <> intCategorythen
          response.write("<tr bgcolor='gray'><td colspan =2>" & objRS("intCategory") & "</td></tr>" & VBCrLf)
          intCategory= objRS("intCategory")
     end if
     response.write("<tr><td>" & objRS("SomeOtherField1") & "</td><td>" & objRS("SomeOtherField2") & "</td></tr>" & VBCrLf)
     objRS.MoveNext
loop

This way, the main heading only gets printed out once. You can increase this to as many levels as you need.

FtB

 

by: joejenkinsjaxPosted on 2006-09-05 at 15:44:16ID: 17459591

That's still keeping the recordset open through the entire display of the page which is upwards of 12-20 seconds depending on the load on the server at that moment.  That's entirely TOO long.

Hmm.  What if I changed my SQL to only get the Category ID and not description of the category and all that; essentially dropping 2 fields (#4 & 5).  Loaded Elements #3, 4 & 5 into another array using a separate query, use an outer loop of the array with categories and the 3 values in that quuery and the inner loop would cycle the data using the first query.

The only problem then is how would I parse out the ones that only have element 3 out of the big array?

jj

 

by: fritz_the_blankPosted on 2006-09-05 at 15:53:23ID: 17459633

Okay, I am with you now.

1) Use the GetRows() method to free the recordset
2) Use the method that I have above with the array

This is not exact but it should put you on the right path

Response.Write("<Table Border=1 cellpadding=2 cellspacing=2>" & VBCrLf)
intCategory= ""
for i=0 to UBound(arrRows,1)
    if arrRows(i,j)  <> intCategory then
        response.write("<tr bgcolor='gray'><td colspan =2>" & arrRows(i,j)& "</td></tr>" & VBCrLf)
        intCategory= objRS("intCategory")
    end if
     Response.Write("<TR>" & VBCrLf)
     for j=0 to UBound(arrRows,2)
          Response.Write("<TD>" & arrRows(i,j) & "</TD>")
     next
     Response.Write("</TR>" & VBCrLf)
next
Response.Write("</Table>")

 

by: joejenkinsjaxPosted on 2006-09-05 at 19:17:03ID: 17460291

The only real problem here is that you can't free the recordset with the above code because you're still calling use of the recordset by initializing intCategory with the "objRS("intCategory") value.  . . Or am I wrong here?

Here's another thought that just popped in my head...

What about creating a sub function that runs a query that limits the data and passes the array out based on the current category.  Now, this would be more connections to the database BUT they would be quick and only on each category.  Would this be a more negetive influence on the server load than keeping the recordset open?

jj

 

by: fritz_the_blankPosted on 2006-09-06 at 07:31:02ID: 17463424

Actually, the above does free the recordset:

arrRows = objRS.GetRows()
objRS.Close
set objRS = Nothing

However, if your query takes 12-15 seconds, that is a different issue.

>>Now, this would be more connections to the database<<

Not at all, you can and should use the same connection object for all recordsets on the page.

>>that runs a query that limits the data<<

We need to look at that more. The more that you limit the data returned from your sql the better.

FtB

 

by: joejenkinsjaxPosted on 2006-09-06 at 07:54:00ID: 17463596

[==Quoted==]
Actually, the above does free the recordset:

arrRows = objRS.GetRows()
objRS.Close
set objRS = Nothing

[=====]

This is true, it does free the recordset.  However, it holds that recordset open and .movenext and other cursor type movements are are an issue with holding that recordset open that long (12-15 seconds on average).  From my testing, querying the database and outputting the rows to the screen using arraws is much faster.

Example: (Same Query, same # of rows returned)

Recordset movement: 14.20 seconds
Arrays Output: 1.06 seconds

The database connection is only open long enough to fill the array with data and then I'm done with the database and recordset in 1 second as opposed to keeping them open for that duration.

jj

 

by: fritz_the_blankPosted on 2006-09-06 at 08:08:19ID: 17463712

How are you outputting the data directly as an array without the use of a recordset?

FtB

 

by: joejenkinsjaxPosted on 2006-10-02 at 07:13:22ID: 17643525

Hi Fritz --
Sorry for letting this one sit so long.  To answer your above question, the recordset is no longer needed after you fill the array with data from the recordset.  Freeing it releases that memory back to the application pool.

I did manage to get the desired results on my own.  I ended up using a 2 array system to accomplish this.  

I had one array filled with the various category types and one filled with the data from the tables I needed.  As I looked through the categories, I would display the header and then run a query to fill the items array with data delimited by categoryID in the WHERE clause.  This worked out much better in the long run looping through this subset of data than keeping the recordset open.  Apparently, rs.movenext is quite hard on the system processor (pegging my 4 processor system at 15-20% for the duration of the query) and by using an array method, the processor never hops over 2%.  MAJOR performance increase.

Thanks again for the assistance.

Joe Jenkins

 

by: fritz_the_blankPosted on 2006-10-08 at 12:29:07ID: 17687023

>>To answer your above question, the recordset is no longer needed after you fill the array with data from the recordset.<<

That was my point, you have to at least open the recordset and use the GetRows() method to populate the array. My suggestion in http:#17458342 and http:#17459633 .

I am glad that you have this sorted.

FtB

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...