Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Looping over query and grouping

Posted on 2006-06-14
6
Medium Priority
?
241 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

719 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