Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Looping over query and grouping

Posted on 2006-06-14
6
Medium Priority
?
245 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
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 1000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
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.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

876 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