Solved

Looping over query and grouping

Posted on 2006-06-14
6
192 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
  • 2
  • 2
  • 2
6 Comments
 
LVL 75

Expert Comment

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

Author Comment

by:Westside2004
Comment Utility
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
Comment Utility
Westside2004,

Which Front end lang you are  using ? I think based on the language, better you move this Qn to that area
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
Comment Utility
>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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
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…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

763 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now