Solved

Looping over query and grouping

Posted on 2006-06-14
6
230 Views
Last Modified: 2008-03-04
Hi,

I have this query I am running and it returns 'x' amount of records grouped by date.

So for example, the current query I have returns this in the recordset:

04/10/06  - California - $54.00
04/10/06 - Alaska - $30.00
04/15/06 - Oregon - $80.00

The problem is I want to only show the date once for a given day.   Each record returned from the query has a date, so on my HTML page I am displaying the records using a LOOP and each record has a date so thus the date displays.  So as opposed to the above I want to have in my display


04/10/06  - California - $54.00
               - Alaska - $30.00
04/15/06 - Oregon - $80.00

This way you can see all the records under a given date.  Is there a way I can do this?

-ws

0
Comment
Question by:Westside2004
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 16905536
You can handle this at the front end easily... Why you wanna do this in sql
0
 
LVL 1

Author Comment

by:Westside2004
ID: 16905630
That is what I figured.... but I am unsure how to do this on the front end.

-ws
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 16905832
Westside2004,

Which Front end lang you are  using ? I think based on the language, better you move this Qn to that area
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16906451
if you have not only group by the date field, but also ordered by the date field, then you simply have to check, for each record, if the value of the date of the current row is the same as the value of the previous record. if it is, simply blank the value
0
 
LVL 1

Author Comment

by:Westside2004
ID: 16908513
Yes angel, you are right, that is what I was trying to to do.   Now that I think more about it, I should be able to get the current row's value, that is easy and maybe subtract 1 to get the previous and then compare....

Thx
-ws
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 16908812
>Now that I think more about it, I should be able to get the current row's value, that is easy and maybe subtract 1 to get the previous and then compare....

here is some vb-like-pseudo-code

recordset.open ( "select ... ")
previous_date = empty

while not recordset.eof
  if previous_date <> recordset.fields("date_field").value then
     --show the value

     -- save the value for the next loop
     previous_date = recordset.fields("date_field").value
  else
     -- do not show the value (blank date)
  end if
  -- show the other fields...
 
  -- loop to next row
  recordset.movenext
wend
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question