Solved

Looping over query and grouping

Posted on 2006-06-14
6
220 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

808 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