473,386 Members | 1,673 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,386 software developers and data experts.

Creating a Group By without functions -- possible?

Hi all,

I'm trying to create a layout of our website for Marketing to review,
and though I know how I want it presented, I'm not sure how to write
the SQL code to make it work. Here's a sample of the View I've written
with all our content:

Level Title ID ParentID
1 Clinics 1
1 Services 2
2 Surgery 1 2
2 ER 2 2
2 Radiology 3 2
2 Clinic 1 4 1
2 Clinic 2 5 1
2 Clinic 3 6 1
3 Heart 1 1
3 Lung 2 1
3 Physicians 3 4
3 Physicians 4 5
3 Physicians 5 6
And the output would basically be this:

Clinics
- Clinic 1
-- Physicians
- Clinic 2
-- Physicians
- Clinic 3
-- Physicians

Services
- Surgery
-- Heart
-- Lung
- ER
- Radilogy

Is there anyway to do this in a SQL statement, or maybe Crystal or
Access? I even tried a Pivot table in Excel, but it wants to sum
stuff, and I'm not working with numbers (sums, counts, etc). Also
since I'm not using any aggrate functions MS SQL is complaining when i
use Group By.

Thanks for any suggestions. Also though the layout is similar, the
items listed above are pulled outta the air. Hopefully I typed up
something that makes since :)

Alex

Jul 23 '05 #1
2 1199
Google Nested Sets Model for trees and buy a copy of TREES &
HIERARCHIES IN SQL.

Jul 23 '05 #2
AK
create table tree(id int, parentID int, nodename varchar(20))
insert into tree values(1,null,'CEO')
insert into tree values(2,1,'leader of team 1')
insert into tree values(3,1,'leader of team 2')
insert into tree values(4,2,'Jerry, team 1')
insert into tree values(5,2,'Cho, team 1')
insert into tree values(6,3,'Raj, team 2')
insert into tree values(7,3,'Kim, team 2')
select * from tree

id parentID nodename
----------- ----------- --------------------
1 NULL CEO
2 1 leader of team 1
3 1 leader of team 2
4 2 Jerry, team 1
5 2 Cho, team 1
6 3 Raj, team 2
7 3 Kim, team 2

(7 row(s) affected)
go
create procedure dbo.display_tree
as
begin
declare @level int, @inserted int

set nocount on

create table #tree(path varchar(20), dashes varchar(20), tree_level
int,
id int, nodename varchar(20))

insert into #tree select convert(varchar(20), id), '', 1, id, nodename
from tree where parentID is null

set @level = 1
set @inserted = 1

while (@inserted > 0) and (@level < 10)
begin
insert into #tree
select path + '.' + convert(varchar(20), tree.id), dashes + '-',
@level+1,
tree.id, tree.nodename
from #tree, tree
where #tree.tree_level = @level
and #tree.id = tree.parentID

set @inserted = @@rowcount
set @level = @level + 1
end

select dashes+nodename from #tree order by path
drop table #tree
end
go
exec dbo.display_tree

----------------------------------------
CEO
-leader of team 1
--Jerry, team 1
--Cho, team 1
-leader of team 2
--Raj, team 2
--Kim, team 2

go
drop procedure dbo.display_tree
drop table tree

Jul 23 '05 #3

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

Similar topics

0
by: Peter D. Dunlap | last post by:
I have a number of web sites on my 2003 server, each of the independent sites (i.e., not subdirectories of the localhost site). The way I have always set these up in the past is: 1. Create a...
12
by: Bill Moran | last post by:
Hey all. I've hit an SQL problem that I'm a bit mystified by. I have two different questions regarding this problem: why? and how do I work around it? The following query: SELECT GCP.id,...
1
by: CES | last post by:
All, I was wondering if someone could point me to a tutorial on creating & accessing functions from within a wrapper function. I've created a group of functions related to a timer event. All...
22
by: ypjofficial | last post by:
Is there any possibility of invoking the member functions of a class without creating an object (or even a pointer to ) of that class. eg. #include <iostream.h> class test { public: void...
6
by: jimbo | last post by:
Dear all, I am more or less new to c++ programing and therefore still have problems with some fundamentals :( At the moment I try to build a GUI-Application with Qt4. Sometimes I have seen in...
2
by: ChrisO | last post by:
I've been pretty infatuated with JSON for some time now since "discovering" it a while back. (It's been there all along in JavaScript, but it was just never "noticed" or used by most until...
6
by: Mohammad Omer | last post by:
Hi, I tried to validate file path without calling file creating functions. Is it possible? How? Regards, -aims
5
by: KewlToyZ | last post by:
Good day, I am stuck in a strange situation. SQL 2000 Server, creating a stored procedure to use in Crystal Reports 11. I am trying to build a report without creating a table or temprorary table in...
1
by: Bartholomew Simpson | last post by:
I know this is a VB.Net ng. But hopefully, someone remembers some classic (VB6) coding - besides I've not had any response when I posted this to the VB6 specific ng. I wrote a C++ librray that I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.