Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Parent-Child Relationship Join
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

154 Posts

Posted - 10/31/2013 :  12:42:08  Show Profile  Reply with Quote
I have a table that contains both Parent and Child records and i'm trying to return the Parent data, if a child record has a parent.
For example (ABC is the child and DEF is the Parent):

ID______CNumber_____PNumber___AR Amount

What I hope to return is this (note Child and Parent records contain the same AR Amount now):

ID______CNumber_____PNumber___AR Amount

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 10/31/2013 :  13:45:02  Show Profile  Reply with Quote
Do you have multiple levels (as in children, grand children, great grand children etc.)? If so, what do you want to display?

If it is just a simple parent child relationship as in your example, this should be sufficient:
	COALESCE(p.ARAmount,c.ARAmount) AS ARAmount
	YourTable c
	LEFT JOIN YourTable p ON c.PNumber = p.CNumber
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000