The raw data in my table consists of an ID column and a column 'IsFolder' which can be 1 or 0, like this: 

```
ID    IsFolder
1     1
2     0
3     0
4     1
5     0
6     0
7     0
8     0
9     0
10    0
11    1
12    0
13    0
14    0
15    1
16    0
17    0

```

The way the code interprets this is that if a line has a 1 for 'IsFolder' then it is a Folder, and all of the tasks below it (until you hit the next Folder) are children of that folder.

What I'd like to have is a Select statement that will just return the ID of the parent folder for all non-folder tasks. So something like:

```
ID    ParentFolder
2     1
3     1
5     4
6     4
7     4
8     4
9     4
10    4
12    11
13    11
14    11
16    15
17    15

```

I'm using MS SQL Server Management Studio 2005. I feel like this is an easy answer to those familiar with using cursors (which I am not). I can't think of any other way to do it but maybe someone else can. Anyway thanks in advance for any answers and sorry if I did something wrong, this is my first post.