I have a table ("title" that stores tree-structure info:
--------------------------------------
id name parent_id has_child
0 CEO -1 1
1 VP-Finance 0 1
2 VP-CIO 0 1
11 Controller 1 0
12 Auditor 1 0
21 Helpdesk Man 2 0
22 Server Man 2 0
--------------------------------------
Now I have another table "title_parents" which stores info derived from the above table:
--------------------------------------
id parents
0 -1
1 -1,0
2 -1,0
11 -1,0,1
12 -1,0,1
21 -1,0,2
22 -1,0,2
--------------------------------------
Now I want to create a store procedure to update "title_parents" table if "title" is updated. The procedure is called proc_reset_parents(id). For example, if I call proc_reset_parents(1), the "parents" column in "title_parents" table with id=11,12,21,22 will be updated.
With this procedure, I can call it in a trigger or anytime I want to update "title_parents" table.
I used to do it in ASP page which I can create an ADO recordset and using recordset filter and bookmark to do what I want. But I don't know how to do the same with T-SQL.
Can you help me out? I am using SQL7 with SP4. Thanks.
--------------------------------------
id name parent_id has_child
0 CEO -1 1
1 VP-Finance 0 1
2 VP-CIO 0 1
11 Controller 1 0
12 Auditor 1 0
21 Helpdesk Man 2 0
22 Server Man 2 0
--------------------------------------
Now I have another table "title_parents" which stores info derived from the above table:
--------------------------------------
id parents
0 -1
1 -1,0
2 -1,0
11 -1,0,1
12 -1,0,1
21 -1,0,2
22 -1,0,2
--------------------------------------
Now I want to create a store procedure to update "title_parents" table if "title" is updated. The procedure is called proc_reset_parents(id). For example, if I call proc_reset_parents(1), the "parents" column in "title_parents" table with id=11,12,21,22 will be updated.
With this procedure, I can call it in a trigger or anytime I want to update "title_parents" table.
I used to do it in ASP page which I can create an ADO recordset and using recordset filter and bookmark to do what I want. But I don't know how to do the same with T-SQL.
Can you help me out? I am using SQL7 with SP4. Thanks.