•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 426,807 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,864 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 1350 | Replies: 6 | Solved
![]() |
•
•
Join Date: Jan 2008
Location: Largo Florida
Posts: 275
Reputation:
Rep Power: 1
Solved Threads: 23
SELECT dbo.Category.Name, dbo.Category.ID
FROM dbo.Category LEFT OUTER JOIN
dbo.Category AS Category_1 ON dbo.Category.ID = Category_1.ParentID
WHERE (Category_1.ParentID IS NULL) B.Sc Computer Science, Helwan University
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
•
•
Join Date: Nov 2007
Location: � Jogja �
Posts: 2,585
Reputation:
Rep Power: 11
Solved Threads: 235
absolutely RamyMahrous.
Last edited by Jx_Man : Feb 8th, 2008 at 10:28 pm.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
•
•
Join Date: Jan 2008
Location: Largo Florida
Posts: 275
Reputation:
Rep Power: 1
Solved Threads: 23
•
•
•
•
SELECT dbo.Category.Name, dbo.Category.ID FROM dbo.Category LEFT OUTER JOIN dbo.Category AS Category_1 ON dbo.Category.ID = Category_1.ParentID WHERE (Category_1.ParentID IS NULL)
Thanks but this is not what i want. i want to pass cat.id as parameter and get all the childrows in it.
example
catid | catname | parentid
1 | 1 | null
2 |1.1 |1
3 |1.2 |1
4 |1.1.1 |2
5 |1.2.1 |3
when i pass a catid = 1 as parameter to procedure i want to get all these records except the first main root one.
Last edited by serkansendur : Feb 11th, 2008 at 3:05 am.
Serkan Şendur
MCAD.NET
MCAD.NET
Sorry for being late as I was in Army last two days..
SELECT Category_1.Name
FROM Category LEFT OUTER JOIN
Category AS Category_1 ON Category.ID = Category_1.ParentID
WHERE (Category_1.ParentID = 1) B.Sc Computer Science, Helwan University
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
•
•
Join Date: Jan 2008
Location: Largo Florida
Posts: 275
Reputation:
Rep Power: 1
Solved Threads: 23
•
•
•
•
Sorry for being late as I was in Army last two days..
SELECT Category_1.Name FROM Category LEFT OUTER JOIN Category AS Category_1 ON Category.ID = Category_1.ParentID WHERE (Category_1.ParentID = 1)
Thanks but this is not what i wanted, i want to see the childs recursively, i want to see the grand childs, childs of grands childs and so on.
Serkan Şendur
MCAD.NET
MCAD.NET
•
•
Join Date: Jan 2008
Location: Largo Florida
Posts: 275
Reputation:
Rep Power: 1
Solved Threads: 23
the t-sql below worked :
set statistics time on set statistics io on declare @Topid_in int -- The top level we want to resolve children for select @topid_in = 1; with Hierarchycte (id, ParentID, name) as (select id, parentid, name from cat where id = @topid_in union all select cat.id, cat.parentid ,cat.name from cat inner join hierarchycte on cat.parentid = hierarchycte.id) select * from hierarchycte
Serkan Şendur
MCAD.NET
MCAD.NET
![]() |
•
•
•
•
•
•
•
•
DaniWeb MS SQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
ajax asp child protection database decimal seperator thousand seperator when using sql server deleting records from ms sql table where columns have duplicate values developer development family hacker management studio 2005 microsoft monitoring software msdn news office pedophiles security software sql sql cache dependency with polling-based invalidation survey vista
- Previous Thread: Function - lose grant
- Next Thread: Error from dbms_lob.writeappend



Linear Mode