自定义函数----建树形关系表
Product表:
字段:pro_id int,
pro_name varchar(50),
pro_parid int
定义函数:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
数据显示:
Pro_id |
Pro_name |
Pro_parid |
100 |
笔记本 |
0 |
105 |
ASUS |
100 |
108 |
ASUS-14寸 |
105 |
112 |
ACER |
100 |
150 |
显示器 |
0 |
160 |
ASUS-15寸 |
105 |
185 |
ACER-14寸 |
112 |
190 |
ASUS-17寸 |
105 |
210 |
TopView |
150 |
250 |
wqwer |
210 |
510 |
werwer |
500 |
610 |
321312 |
600 |
710 |
3213 |
700 |
888 |
88 |
710 |
运行结果:select * from fnprotree(0,0)
|
Pro_id |
Pro_name |
Pro_parid |
Flag |
curlevel |
Sobsum |
orderNo |
100 |
笔记本 |
0 |
-1 |
0 |
2 |
1 |
100 |
105 |
ASUS |
100 |
-1 |
1 |
3 |
2 |
105 |
108 |
ASUS-14寸 |
105 |
-1 |
2 |
0 |
3 |
108 |
160 |
ASUS-15寸 |
105 |
0 |
2 |
0 |
4 |
160 |
190 |
ASUS-17寸 |
105 |
1 |
2 |
0 |
5 |
190 |
112 |
ACER |
100 |
1 |
1 |
1 |
6 |
112 |
185 |
ACER-14寸 |
112 |
1 |
2 |
0 |
7 |
185 |
150 |
显示器 |
0 |
1 |
0 |
1 |
8 |
150 |
210 |
TopView |
150 |
1 |
1 |
1 |
9 |
210 |
250 |
wqwer |
210 |
1 |
2 |
0 |
10 |
250 |
By--demonlion