Click here to Skip to main content
15,895,799 members
Home / Discussions / Database
   

Database

 
GeneralRe: Can anyone help me with this one? Pin
Suresh Prasad3-Dec-04 11:29
Suresh Prasad3-Dec-04 11:29 
GeneralRe: Can anyone help me with this one? Pin
Mike Ellison3-Dec-04 11:48
Mike Ellison3-Dec-04 11:48 
GeneralRe: Can anyone help me with this one? Pin
Suresh Prasad3-Dec-04 11:57
Suresh Prasad3-Dec-04 11:57 
GeneralUploading Large numbers of records Pin
mjackson113-Dec-04 8:07
mjackson113-Dec-04 8:07 
GeneralRe: Uploading Large numbers of records Pin
Alex Korchemniy4-Dec-04 16:56
Alex Korchemniy4-Dec-04 16:56 
GeneralRe: Uploading Large numbers of records Pin
mjackson118-Dec-04 9:42
mjackson118-Dec-04 9:42 
GeneralADO.NET columns are magic numbers.. Pin
giorgos_gr3-Dec-04 5:09
giorgos_gr3-Dec-04 5:09 
GeneralSQL Tree Hierarchy Problem Pin
Dirk Kok2-Dec-04 22:24
sussDirk Kok2-Dec-04 22:24 
Hi
Please help me out here with some hierarchies. It’s blowing my mind.
Here’s the table…

CREATE TABLE [dbo].[Tree] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[ParentID] [int] NULL ,
[Lineage] [varchar] (50) NULL ,
[Name] [varchar] (50) NOT NULL
) ON [PRIMARY]
GO


Here’s some data…

SET IDENTITY_INSERT Tree ON

INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (1, NULL, '.0001.', 'Root')
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (2, 1, '.0001.0002.', 'I')
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (3, 1, '.0001.0003.', 'H')
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (4, 1, '.0001.0004.', 'G')
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (5, 2, '.0001.0002.0005.', 'F')
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (6, 2, '.0001.0002.0006.', 'E')
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (7, 2, '.0001.0002.0007.', 'D')
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (8, 4, '.0001.0004.0008.', 'C')
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (9, 4, '.0001.0004.0009.', 'B')
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (10, 3, '.0001.0003.0010.', 'A')

SET IDENTITY_INSERT Tree OFF

You have the above tree data. You can ignore the lineage if you don’t want to work with it.


There problem is as follows…


Please sort the tree nodes according to the hierarchy, BUT the nodes must also be in ALPHABETICAL order.


So “SELECT * FROM Tree ORDER BY Lineage” will look like so…


Root
I
F
E
D
H
A
G
C
B

But I need it to be sorted in that hierarchy but also alphabetically like so

Root
G
B
C
H
A
I
D
E
F


Can someone figure this out for me please?

Regards
Dirk









GeneralRe: SQL Tree Hierarchy Problem Pin
Michael Potter3-Dec-04 4:34
Michael Potter3-Dec-04 4:34 
GeneralRe: SQL Tree Hierarchy Problem Pin
Chris Meech3-Dec-04 6:44
Chris Meech3-Dec-04 6:44 
GeneralStored Proc and SqlDataAdapter Pin
ccosser2-Dec-04 22:03
ccosser2-Dec-04 22:03 
GeneralAttaching a database to MSDE Pin
mattie202-Dec-04 20:31
mattie202-Dec-04 20:31 
GeneralNested Transaction with SQL Server Pin
Wouter van Eck2-Dec-04 5:21
Wouter van Eck2-Dec-04 5:21 
QuestionHow can i avaoid negative values in SQL? Pin
john kuruvila2-Dec-04 5:14
john kuruvila2-Dec-04 5:14 
AnswerRe: How can i avaoid negative values in SQL? Pin
Colin Angus Mackay2-Dec-04 6:42
Colin Angus Mackay2-Dec-04 6:42 
GeneralRe: How can i avaoid negative values in SQL? Pin
john kuruvila2-Dec-04 7:30
john kuruvila2-Dec-04 7:30 
Generalnot allowing negative values Pin
sujithapril2-Dec-04 5:10
sujithapril2-Dec-04 5:10 
GeneralRe: not allowing negative values Pin
Colin Angus Mackay2-Dec-04 6:41
Colin Angus Mackay2-Dec-04 6:41 
GeneralRe: not allowing negative values Pin
sujithapril2-Dec-04 7:23
sujithapril2-Dec-04 7:23 
GeneralRe: not allowing negative values Pin
Colin Angus Mackay2-Dec-04 7:26
Colin Angus Mackay2-Dec-04 7:26 
GeneralRe: not allowing negative values Pin
sujithapril2-Dec-04 7:50
sujithapril2-Dec-04 7:50 
GeneralRe: not allowing negative values Pin
Colin Angus Mackay2-Dec-04 7:59
Colin Angus Mackay2-Dec-04 7:59 
GeneralRecordset "LIKE" filter of a number column Pin
Menny Even Danan1-Dec-04 21:51
Menny Even Danan1-Dec-04 21:51 
GeneralRe: Recordset "LIKE" filter of a number column Pin
jlawren72-Dec-04 5:27
jlawren72-Dec-04 5:27 
Generalcan't DELETE records in excel Pin
scoroop1-Dec-04 11:15
scoroop1-Dec-04 11:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.