Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing fields in two different rows 2

Status
Not open for further replies.

Adammon

Programmer
Nov 10, 2001
9
CA

I'm rewriting some ASP for our corporate intranet and there is a lot of redundant information that appears in the "News" section (Populated from an SQL server that I don't have access too) Information such as "date submitted" that I think should be rolled up into a single header.

What I have is this:

12-01-2005 News item 5
12-01-2005 News Item 4
11-30-2005 News Item 3
11-30-2005 News Item 2
11-30-2005 News Item 1

Each piece of that display is pulled from SQL in a recordset object and then displayed through simple ASP.

What I want to see is:

12-01-2005
News Item 5
News Item 4
11-30-2005
News Item 3
News Item 2
News Item 1

I've been able to do this in other languages/reporting systems I work in, but for the life of me can't figure it out in ASP.

My pseudocode below:

If RS(Date) <> RS.previousrow(Date) or RS.BOF Then
Response.Write(Date)
(space)(space)(Space)Response.Write(NewsItem)
Else
(space)(space)(Space)Response.Write(NewsItem)
End if

The only thing I can't figure out is if it's possible to do this movement in ASP, and what the syntax is to do it.

Thanks a bunch.
 
similar topic:

thread333-1164069

see my solution at the end of the thread...

try it out and let me know if it works for you...

-DNG
 
Hmm, while there are at least a few dozen threads in the past that deal with this, I don't think that one resolves the problem at hand without adding a second set of output functions to the inner loop. This could easily be resolved in one loop, though still similar to DNGs solution:
Code:
Dim lastVal
Do Until rs.EOF
   If rs("yourField") <> lastVal
      'this occurs on first loop and subsequent loops when the "yourField" field changes values
      Response.Write "<b>" & rs("yourField") & "</b><br/>"
      lastVal = rs("yourField")
   End If

   'output that occurs on every loop
   Response.Write "--- " & rs("yourField") & "<br/>"

   rs.MoveNext
Loop

This is easily modifiable to output a table-based layout or section-based divs without the cost of additional condition checks necessary for a nested loop.

-T

barcode_1.gif
 
Thanks, I hadn't thought of moving through the record set like that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top