SQLTeam.com | Weblogs | Forums

Create folder structure in database table

sql2012

#1

I have folder A/B/C
wants to store in table

1 A NULL
2 B 1
3 C 2


#2

your questions seems not complete, what is your question?


#3

using my crystal ball and also fnParseList from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033

declare    @folder varchar(10)    = 'A/B/C'

select    ID = RowID, 
    folder = Data, 
    parent = nullif(RowID - 1, 0)
from    dbo.fnParseList('/', @folder)

-- Result
ID     folder    parent      
------ --------- ----------- 
1      A         NULL
2      B         1
3      C         2

(3 row(s) affected)