i need to create Function that will return the super parent of a given id from a table
the table look like table1 (id, parentId, someData) the parentId is related to the id
for example i have 1 - 2 - 3 - 4 id of each row
- id parentId
- 1 null
- 2 1
- 3 2
- 4 3
now when i give the Function 4 as parameter it will return 1
i'm using SQL server 2008
how can this be done