Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 12th, 2003, 12:44 AM
Registered User
 
Join Date: Oct 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Nested Group

SELECT DISTINCT company_code.department, " _
& "courseCat.link_name " & _
"FROM company_code " & _
"INNER JOIN courseCat ON company_code.group_id= courseCat.group_id " & _
"WHERE courseCat.company_id = " & company_id & _
"GROUP BY company_code.department, courseCat.link_name" & _
" ORDER BY courseCat.link_name

The code above will print the department and link_name on each row.
i.e. Department 1
Course 1

Department 1
Course 2
etc.

Does anyone know how I would write the code to print the department as a header followed by the associated link_name? i.e.
Department 1
course 1
course 2

Department 2
course 1
course 2

etc..
 
Old October 12th, 2003, 06:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Can't be done.

SQL returns resultsets which are a homogenous collection of rows all with the same columns. Each row, of course, has distinct values, but every row is structurally identical to every other row.

You are asking that the rows be different.

Your problem is best handled at the client...

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old October 12th, 2003, 12:17 PM
Registered User
 
Join Date: Oct 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jeff, that gave me another idea. I split the query into 2 separate queries and iterate through the course listings until EOF and then jump back to the first query to grab another department and iterate through the 2nd query again until EOF. It works perfectly.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Group Within another Group, xslt1.0 jhansib4u BOOK: XSLT Programmer's Reference, 2nd Edition 4 November 22nd, 2007 01:24 AM
Restart new group number in Group Footer sukarso Crystal Reports 2 October 13th, 2006 12:11 PM
nested for hastikeyvan Classic ASP Professional 1 July 27th, 2006 06:28 PM
Group by , Sub Group by and Sum mateenmohd SQL Server 2000 1 March 29th, 2005 09:51 AM
Nested If pans Access 4 December 10th, 2004 12:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.