473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Group Sql results in Row Heading format

I've been struggling with this for a while now. But I want to display my
query results in a table where they are grouped by project. I am using a do
while loop but it not achieving the look I want.

This is what I got:
Project Employee Name OT Hours
Project 1 Employee A 7
Project 1 Employee C 5
Project 1 Employee D 3
Project 2 Employee A 8
Project 2 Employee B 4
Project 2 Employee E 6

This is what I would like or as it has been expressed to me is needed:
Project 1
Employee Name OT Hours
Employee A 7
Employee C 5
Employee D 3

Project 2
Employee Name OT Hours
Employee A 8
Employee B 4
Employee E 6

--
Message posted via WebmasterKB.com
http://www.webmasterkb.com/Uwe/Forums.aspx/asp/200703/1

Mar 2 '07 #1
8 3360
Mike Will via WebmasterKB.com wrote on 02 mrt 2007 in
microsoft.public.inetserver.asp.general:
I've been struggling with this for a while now. But I want to display
my query results in a table where they are grouped by project. I am
using a do while loop but it not achieving the look I want.

This is what I got:
Project Employee Name OT Hours
Project 1 Employee A 7
Project 1 Employee C 5
Project 1 Employee D 3
Project 2 Employee A 8
Project 2 Employee B 4
Project 2 Employee E 6

This is what I would like or as it has been expressed to me is needed:
Project 1
Employee Name OT Hours
Employee A 7
Employee C 5
Employee D 3
sql = "select EmployeeName,OTHours from tbl where Project = 'Project1' "&_
"order by OTHours desc"
>
Project 2
Employee Name OT Hours
Employee A 8
Employee B 4
Employee E 6
sql = "select EmployeeName,OTHours from tbl where Project = 'Project2' "&_
"order by OTHours desc"

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 2 '07 #2
Evertjan. wrote:
Mike Will via WebmasterKB.com wrote on 02 mrt 2007 in
microsoft.public.inetserver.asp.general:
>I've been struggling with this for a while now. But I want to
display my query results in a table where they are grouped by
project. I am using a do while loop but it not achieving the look I
want.

This is what I got:
Project Employee Name OT Hours
Project 1 Employee A 7
Project 1 Employee C 5
Project 1 Employee D 3
Project 2 Employee A 8
Project 2 Employee B 4
Project 2 Employee E 6

This is what I would like or as it has been expressed to me is
needed: Project 1
Employee Name OT Hours
Employee A 7
Employee C 5
Employee D 3

sql = "select EmployeeName,OTHours from tbl where Project =
'Project1' "&_ "order by OTHours desc"
>>
Project 2
Employee Name OT Hours
Employee A 8
Employee B 4
Employee E 6

sql = "select EmployeeName,OTHours from tbl where Project =
'Project2' "&_ "order by OTHours desc"
You're not serious are you?

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Mar 2 '07 #3
Thank you but I would hope there is a more efficient way.

Here is my code where I have begun building a table of information from my
recordset. I'm sure I just need some help thinking this through.

<table width="100%">
<%If rs2.RecordCount = 0 Then%>
<tr>
<td colspan="9" bgcolor="#ECE9D8" id="headtext"><h3>No projects within 10
miles <%=Request.QueryString("qryProject")%></h3></td>
</tr>
</table>
<%rs2.Close
Else%>
<tr>
<td colspan="9"><h4>Projects within 10 Miles of <%=Request.QueryString
("qryproject")%></h4></td>
</tr>
<tr bgcolor="#0099FF">
<th width="20%">Project</th>
<th width="20%">Employee</th>
<th width="20%">Project Description</th>
<th width="20%">Overtime Balance</th>
<th width="20%">Primary Contact Number</th>
</tr>
<% 'Loop through the recordset
Do While not rs2.EOF
'Write the HTML to display the current record in the recordset%>
<table width="100%">
<tr bgcolor="#CCCCCC">
<td width="20%" align="center"><%=rs2("Within10Miles")%></td>
<td width="20%" align="center"><%=rs2("Employee")%></td>
<td width="20%" align="center"><%=rs2("10MileDesc")%></td>
<td width="20%" align="center"><%=rs2("OTBal")%></td>
<td width="20%" align="center"><%=rs2("Phone1")%></td>
</tr>
</table>

--
Message posted via WebmasterKB.com
http://www.webmasterkb.com/Uwe/Forums.aspx/asp/200703/1

Mar 2 '07 #4
Bob Barrows [MVP] wrote on 02 mrt 2007 in
microsoft.public.inetserver.asp.general:
Evertjan. wrote:
>Mike Will via WebmasterKB.com wrote on 02 mrt 2007 in
microsoft.public.inetserver.asp.general:
>>I've been struggling with this for a while now. But I want to
display my query results in a table where they are grouped by
project. I am using a do while loop but it not achieving the look I
want.

This is what I got:
Project Employee Name OT Hours
Project 1 Employee A 7
Project 1 Employee C 5
Project 1 Employee D 3
Project 2 Employee A 8
Project 2 Employee B 4
Project 2 Employee E 6

This is what I would like or as it has been expressed to me is
needed: Project 1
Employee Name OT Hours
Employee A 7
Employee C 5
Employee D 3

sql = "select EmployeeName,OTHours from tbl where Project =
'Project1' "&_ "order by OTHours desc"
>>>
Project 2
Employee Name OT Hours
Employee A 8
Employee B 4
Employee E 6

sql = "select EmployeeName,OTHours from tbl where Project =
'Project2' "&_ "order by OTHours desc"

You're not serious are you?
Sorry?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 2 '07 #5
Evertjan. wrote:
>>
You're not serious are you?

Sorry?
You ARE serious? You would actually run separate sql statements for each
project ID? Rather than retrieving them all and looping to display them in
groups?

To the OP: I will post a script to do this later - it's simply a matter of
keeping track of which project ID you are on when displaying the items.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Mar 2 '07 #6
Mike Will via WebmasterKB.com wrote:
I've been struggling with this for a while now. But I want to
display my query results in a table where they are grouped by
project. I am using a do while loop but it not achieving the look I
want.

This is what I got:
Project Employee Name OT Hours
Project 1 Employee A 7
Project 1 Employee C 5
Project 1 Employee D 3
Project 2 Employee A 8
Project 2 Employee B 4
Project 2 Employee E 6

This is what I would like or as it has been expressed to me is needed:
Project 1
Employee Name OT Hours
Employee A 7
Employee C 5
Employee D 3

Project 2
Employee Name OT Hours
Employee A 8
Employee B 4
Employee E 6
I'm assuming your sql statement looks something like this:

sql = "select Project, EmployeeName,OTHours from tbl "&_
"order by Project ,OTHours desc"

I would use GetRows to read the recordset into an array and process it like
this:

dim rs, ar, CurrProj, NewProj

set rs=conn.execute(sql,,1)
if not rs.eof then ar=rs.GetRows
rs.close:set rs=nothing
conn.close: set conn=nothing
dim titles
titles="<tr><th>Employee Name</th>" & _
"<th>OT Hours</th></tr>"
if isarray(ar) then
CurrProj = ar(0,0)
Response.Write "<table border=""1"" style=""" & _
"bordercollapse:collapse""><tr><th colspan=2>" & _
CurrProj & "</th></tr>"
Response.Write titles
for i=0 to ubound(ar,2)
NewProj=ar(0,i)
if CurrProj <NewProj then
CurrProj=NewProj
Response.Write "<tr><th colspan=2>" & _
CurrProj & "</th></tr>"
Response.Write titles
end if
Response.Write "<tr><td>" & ar(1,i) & "</td>" & _
"<td>" & ar(2,i) & "</td></tr>"
next
Response.Write "</table>"
else
Response.Write "No Records Were Retrieved"
end if

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Mar 2 '07 #7
Bob Barrows [MVP] wrote on 02 mrt 2007 in
microsoft.public.inetserver.asp.general:
Evertjan. wrote:
>>>
You're not serious are you?

Sorry?

You ARE serious? You would actually run separate sql statements for
each project ID? Rather than retrieving them all and looping to
display them in groups?
Sure, but as in all developing you have to take it one step at a time, Bob,
and building a page with two or three "project" groups as discrete SQL's
will convince you [general you] what you want is feasable.

Then you can choose for a system whith an outer and an inner loop.

and finally make a develish comlicated SQL that can do the whole
kakamadoodle in one go.

I am sure you [specific you], Bob, can skip those intermediate steps in
your head, but will that be educational?
To the OP: I will post a script to do this later - it's simply a
matter of keeping track of which project ID you are on when displaying
the items.
I am sure most OP's will be glad for that, and they will not loose any
sleep, but will they be able to do the job themselves next time?

And no, I am not totally serious, where would the fun be in that?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 2 '07 #8
Yes that is what my sql statement looks like. I experimented with an array
and just couldn't pull it off. I'm not above getting help so I posted the
question. Thanks Bob I'll give it a shot.

--
Message posted via WebmasterKB.com
http://www.webmasterkb.com/Uwe/Forums.aspx/asp/200703/1

Mar 5 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mike Nolan | last post by:
I notice that 7.4 doesn't do default ordering on a 'group by', so you have to throw in an 'order by' clause to get the output in ascending group order. Is this something that most RDB's have...
1
by: Alicia | last post by:
I basically wanted something that would do a count of the dates, then group them by their week name.. BEFORE: Resource Date Total number of times that date Appeared (Count) 4/3/03 ...
3
by: Lee | last post by:
I have a crosstab query that lists the number of patients(DECnum)by County. County is my Row Heading. Currently, the Column heading is Age in months, which is set at one month intervals. I would...
9
by: Terry E Dow | last post by:
Howdy, I am having trouble with the objectCategory=group member.Count attribute. I get one of three counts, a number between 1-999, no member (does not contain member property), or 0. Using...
3
by: dennist685 | last post by:
Format text as a heading I'm progressing through a walkthrough on DetailsView control Early on it says Type Edit Employees, select the text, and then format the text as a heading. I clicked...
2
by: kirke | last post by:
Hi, I have a datetime column named dtDateTime. its format is "Oct 27 2006 12:00:00 " I want to group by only date part of it and count my code is $sql1="SELECT ...
1
by: digidave | last post by:
I am keenly aware that my coding skills are extremely noob but please indulge me a second.. Take a look at these queries.. $sql = "SELECT DISTINCT year FROM _current_floats_config WHERE active =...
1
by: boarderchic15 | last post by:
Hi- I have the following XML structure: <?xml version="1.0" encoding="UTF-8"?> <content> <type content_type="Listing"/> <faq_listing> <heading>Benefits</heading>...
5
by: CindySue | last post by:
I'm using a subform linked to the main form by a bidder number field. In the subform, I added a group header and put the field LS in it so that it would list all records designated as Live first...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.