Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-02-10 : 19:30:59
|
| Mark writes "Given the following table:TABLE FOO:String parentOIDString childOIDI need to create a recursive sql statement in which given a childOID, I need to get all of its parents, and all of its parents parents.Can you help?" |
|
|
aiken
Aged Yak Warrior
525 Posts |
Posted - 2002-02-10 : 22:52:20
|
| I haven't tested this (or even checked for typos), but I think you're looking for something like this, assuming you're looking for a comma delited answerselect dbo.f_Parents('childOID')----CREATE FUNCTION dbo.f_Parents(@childOID int) ASreturns varchar(500)DECLARE @vcRet varchar(500),vcParent varchar(500)select @vcParent=parentOID from FOO where childOID=@childOIDif @vcParent is not null select @vcRet=dbo.f_Parents(@vcParent) + ',' + @vcParentreturn @vcRet |
 |
|
|
|
|
|