Showing posts with label children. Show all posts
Showing posts with label children. Show all posts

Friday, February 10, 2012

Build SQL statement to show some tiers

in my relational sql db structure I have some items and its children, grandchildren items
to print these values do i need to build one sql statement for each tier?
into my sproc i tried something as following but it returns me only the last tier
SELECT * FROM A
INNER JOIN
B ON A.field1 = B.field2
INNER JOIN
C ON A.filed3 = C.field4
WHERE A.filed1 = @.myParam

thanks a lot

I'm not sure if you're looking to query an hierarchy but if so:
It sounds like you've got a table that's representing a hierarchial relationship, ie something like this:
create table myTable
(
id int,
parentID int null,
value varchar(30)
)
There are a bunch of good articles on sqlteam. Take a look at this one:
http://www.sqlteam.com/item.asp?ItemID=8866
Hope this helps,