sqlserver 递归删除组织结构树

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/// <summary>
        /// 递归删除岗位节点
        /// </summary>
        /// <param name="PK_ROLE_ID"></param>
        /// <param name="isPost"></param>
        /// <returns></returns>
        public bool DeletePosts(int PK_ROLE_ID)
        {
             
            StringBuilder strSql=new StringBuilder();
 
 
             strSql.Append("   WITH post(PK_ROLE_ID, ROLE_FATHER, ROLE_NAME) AS ");
             strSql.Append("       (    ");
             strSql.Append("           SELECT  R.PK_ROLE_ID, R.ROLE_FATHER, R.ROLE_NAME");
             strSql.Append("           FROM [ROLE] R WHERE PK_ROLE_ID=@PK_ROLE_ID");
             strSql.Append("           UNIon ALL");
             strSql.Append("           SELECT sub.PK_ROLE_ID, sub.ROLE_FATHER, sub.ROLE_NAME");
             strSql.Append("           FROM [ROLE] sub, post super");
             strSql.Append("           WHERE sub.ROLE_FATHER = super.PK_ROLE_ID");
             strSql.Append("       )");
             strSql.Append("   delete from [ROLE] where PK_ROLE_ID in(");
             strSql.Append("   select PK_ROLE_ID from post");
             strSql.Append("   )");
 
            SqlParameter[] parameters = {
                    new SqlParameter("@PK_ROLE_ID", SqlDbType.Int,4)
};
            parameters[0].Value = PK_ROLE_ID;
 
            int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

sqlserver 递归删除组织结构树,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。