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 递归删除组织结构树,布布扣,bubuko.com

sqlserver 递归删除组织结构树

上一篇:MySQL基础day01_MySQL基础-Redhat Enterprise 6.4


下一篇:ThinkPHP学习(三)配置PHP5支持MySQL,连接MySQL数据库