SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 5th, 2004, 06:59 AM
android android is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 9 android User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How do I display query results the way I want 'em?

I have a junction table which lists names in the first column and skills in the second column e.g.:

Name | Skill

Name 1 | Skill 1
Name 1 | Skill 2
Name 1 | Skill 5
Name 2 | Skill 1
Name 2 | Skill 4
Name 3 | Skill 3
Name 3 | Skill 6

I want to display results on a webpage in the following format:

Name 1: Skill 1, Skill 2, Skill 5
Name 2: Skill 1, Skill 4
Name 3: Skill 3, Skill 6

I've been told I need to use GROUP BY, but this expects an arthmetic operator or aggregate function like SUM. However, the data type is Text. How do I get what I need?

Reply With Quote
  #2  
Old August 5th, 2004, 12:08 PM
RvCNet RvCNet is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Holland
Posts: 37 RvCNet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 19 m 18 sec
Reputation Power: 5
you could try something like this in ASP:
use an SQL query like
Code:
 
SELECT * FROM table ORDER BY Name, Skill

And display it like this:
Code:
<table>
<tr>
<th>name</th><th>skills</th></tr><%


Do While Not oResult.EOF
sName = oResult.fields("Name").value %> <tr> <td><% = sName %> </td> <td> <% = oResult.fields("Skill").value oResult.MoveNext Do While Not oResult.EOF AND oResult.Fields("Name").value = sName %>
, <% = oResult.fields("Skill").value oResult.MoveNext
Loop %> </td></tr><%
Loop%> </table>

Reply With Quote
  #3  
Old August 19th, 2004, 03:38 PM
johnny_wsdc johnny_wsdc is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 5 johnny_wsdc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How would you add another field?

Ive been trying to use what you did RvCNet but I modified it...
SQL:

[CODE] <table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>
<th><span class="style1">Name</span></th>
<th><span class="style1">Skills</span></th>
</tr>
<%
priorName = ""
Do While Not oRS.EOF
sName = oRS.fields("BName").value
work = oRS.fields("WorkType").value
If sName <> priorName Then
If priorName <> "" Then
%>
</td>
</tr>
<%
End If
%>
<tr><td colspan="2">&nbsp;</td></tr>
<tr>
<td valign="top" nowrap><span class="style1"><b><%= sName %></b><br>
<%=oRS("BmailingAddress")%><br>
<%=oRS("BCity")%>, <%=oRS("BState")%>&nbsp;<%=oRS("BZIP")%>
<% if oRS("BWebSite") <> "" then %>
<br>
<b>Web Site:</b> <a href="http://<%=oRS("BWebSite")%>" target="_blank"><%=oRS("BWebSite")%></a><% end if %><br>
<b>Phone:</b> <%=oRS("BPhone")%><br>
<b>FAX:</b> <%=oRS("BFAX")%>
</span></td>
<td valign="top"><span class="style1"><%= work%>
<%
priorName = sName
Else
%>
, <%=work%>
<%
End If
oRS.MoveNext
Loop
%>
</span>
</td>
</tr>
</td>
</tr>
</table>
CODE]

My question now is how can I include another field very similar to the "WorkType"...

Thanks...

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > How do I display query results the way I want 'em?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT