select distinct cBdlb,cTableName,cBdlbName,cbh,dSqrq,cMenuId,U.cUserName,cRyfl from ( select 'Gagzsqb' as cBdlb,'Gagzsqb' as cTableName,cBdlbName,cGabh as cbh,dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl from Gagzsqb g , Shpzb s where  s.cBdlb='Gagzsqb' and  (g.iState=1 or g.iState=4) and g.cSgzdm='17' and S.cSgzdm='17' and s.cShr in ('7') Union  select 'Gajazybg' as cBdlb,'Gajazybg' as cTableName,cBdlbName,cGabh as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl from Gajazybg g ,  Shpzb s   where  s.cBdlb='Gajazybg' and  (g.iState=1 or g.iState=4) and g.cSgzdm='17' and S.cSgzdm='17' and s.cShr in ('7') Union  select 'Xzgzsqb' as cBdlb,'Xzgzsqb' as cTableName,cBdlbName,cXzbh as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl from Xzgzsqb g ,  Shpzb s    where  s.cBdlb='Xzgzsqb' and  (g.iState=1 or g.iState=4) and g.cSgzdm='17' and S.cSgzdm='17' and s.cShr in ('7') Union  select 'Xzgzjapgb' as cBdlb,'Xzgzjapgb' as cTableName,cBdlbName,cXzbh as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl from Xzgzjapgb g ,  Shpzb s    where  s.cBdlb='Xzgzjapgb' and  (g.iState=1 or g.iState=4) and g.cSgzdm='17' and S.cSgzdm='17' and s.cShr in ('7') Union  select 'Sqgzsqb' as cBdlb,'Sqgzsqb' as cTableName,cBdlbName,cSqgzbh as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl from Sqgzsqb g ,  Shpzb s    where  s.cBdlb='Sqgzsqb' and  (g.iState=1 or g.iState=4) and g.cSgzdm='17' and S.cSgzdm='17' and s.cShr in ('7') Union  select 'Sqgzpgbg' as cBdlb,'Sqgzpgbg' as cTableName,cBdlbName,cSqgzbh as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl from Sqgzpgbg g , Shpzb s    where  s.cBdlb='Sqgzpgbg' and  (g.iState=1 or g.iState=4) and g.cSgzdm='17' and S.cSgzdm='17' and s.cShr in ('7') Union  select '20100221095459106' as cBdlb,'Qjb' as cTableName,'请假申请' as cBdlbName, cast(g.iAutoId as varchar(20))  as cbh, g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,g.iZw  From Qjb g, GetChildsZzjg('17') as  Zzjg ,Sys_userOrg U, Shpzb s  where  g.cUserCode <>'scyc18001' and s.cBdlb='20100221095459106' and g.iZw='1'and g.cUserCode=U.cUserCode and U.cZzjgdm=Zzjg.cZzjgdm and (g.iState=1 or g.iState=4)  and s.cShr in( '7') Union  select '20100221095459106' as cBdlb,'Qjb' as cTableName,'请假申请' as cBdlbName, cast(g.iAutoId as varchar(20))  as cbh, g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,g.iZw  From Qjb g, GetChildsZzjg('17') as  Zzjg ,Sys_userOrg U, Shpzb s  where  g.cUserCode <>'scyc18001' and s.cBdlb='20100221095459106' and g.iZw='2'and g.cUserCode=U.cUserCode and U.cZzjgdm=Zzjg.cZzjgdm and (g.iState=1 or g.iState=4)  and s.cShr in( '7') Union  select '20100221095459106' as cBdlb,'Qjb' as cTableName,'请假申请' as cBdlbName, cast(g.iAutoId as varchar(20))  as cbh, g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,g.iZw  From Qjb g, GetChildsZzjg('17') as  Zzjg ,Sys_userOrg U, Shpzb s  where  g.cUserCode <>'scyc18001' and s.cBdlb='20100221095459106' and g.iZw='3'and g.cUserCode=U.cUserCode and U.cZzjgdm=Zzjg.cZzjgdm and (g.iState=1 or g.iState=4)  and s.cShr in( '7') Union  select '20100221095459106' as cBdlb,'Qjb' as cTableName,'请假申请' as cBdlbName, cast(g.iAutoId as varchar(20))  as cbh, g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,g.iZw  From Qjb g, GetChildsZzjg('17') as  Zzjg ,Sys_userOrg U, Shpzb s  where  g.cUserCode <>'scyc18001' and s.cBdlb='20100221095459106' and g.iZw='4'and g.cUserCode=U.cUserCode and U.cZzjgdm=Zzjg.cZzjgdm and (g.iState=1 or g.iState=4)  and s.cShr in( '7') Union  select '20100221095459106' as cBdlb,'Qjb' as cTableName,'请假申请' as cBdlbName, cast(g.iAutoId as varchar(20))  as cbh, g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,g.iZw  From Qjb g, GetChildsZzjg('17') as  Zzjg ,Sys_userOrg U, Shpzb s  where  g.cUserCode <>'scyc18001' and s.cBdlb='20100221095459106' and g.iZw='5'and g.cUserCode=U.cUserCode and U.cZzjgdm=Zzjg.cZzjgdm and (g.iState=1 or g.iState=4)  and s.cShr in( '7') Union  select '20100221095459106' as cBdlb,'Qjb' as cTableName,'请假申请' as cBdlbName, cast(g.iAutoId as varchar(20))  as cbh, g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,g.iZw  From Qjb g, GetChildsZzjg('17') as  Zzjg ,Sys_userOrg U, Shpzb s  where  g.cUserCode <>'scyc18001' and s.cBdlb='20100221095459106' and g.iZw='6'and g.cUserCode=U.cUserCode and U.cZzjgdm=Zzjg.cZzjgdm and (g.iState=1 or g.iState=4)  and s.cShr in( '7') Union  select '20100225110946919' as cBdlb,'Qjb' as cTableName,'请假' as cBdlbName, cast(g.iAutoId as varchar(20))  as cbh, g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,g.iZw  From Qjb g, GetChildsZzjg('17') as  Zzjg ,Sys_userOrg U, Shpzb s  where  g.cUserCode <>'scyc18001' and s.cBdlb='20100225110946919' and g.iZw='1' and datediff(d,g.dQjkssj,g.dQjjssj) >=1 and g.cUserCode=U.cUserCode and U.cZzjgdm=Zzjg.cZzjgdm and (g.iState=1 or g.iState=4)  and s.cShr in( '7') Union  select '20100225110946919' as cBdlb,'Qjb' as cTableName,'请假' as cBdlbName, cast(g.iAutoId as varchar(20))  as cbh, g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,g.iZw  From Qjb g, GetChildsZzjg('17') as  Zzjg ,Sys_userOrg U, Shpzb s  where  g.cUserCode <>'scyc18001' and s.cBdlb='20100225110946919' and g.iZw='4' and datediff(d,g.dQjkssj,g.dQjjssj) >=1 and g.cUserCode=U.cUserCode and U.cZzjgdm=Zzjg.cZzjgdm and (g.iState=1 or g.iState=4)  and s.cShr in( '7') Union  select '20100209110900655' as cBdlb,'Xjb' as cTableName,'销假' as cBdlbName, cast(g.iQjbId as varchar(20))  as cbh, g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,g.iZw  From Xjb g, GetChildsZzjg('17') as  Zzjg ,Sys_userOrg U, Shpzb s  where  g.cUserCode <>'scyc18001' and s.cBdlb='20100209110900655' and g.iZw='1'and g.cUserCode=U.cUserCode and U.cZzjgdm=Zzjg.cZzjgdm and (g.iState=1 or g.iState=4)  and s.cShr in( '7') Union  select '20100209110900655' as cBdlb,'Xjb' as cTableName,'销假' as cBdlbName, cast(g.iQjbId as varchar(20))  as cbh, g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,g.iZw  From Xjb g, GetChildsZzjg('17') as  Zzjg ,Sys_userOrg U, Shpzb s  where  g.cUserCode <>'scyc18001' and s.cBdlb='20100209110900655' and g.iZw='2'and g.cUserCode=U.cUserCode and U.cZzjgdm=Zzjg.cZzjgdm and (g.iState=1 or g.iState=4)  and s.cShr in( '7') Union  select '20100209110900655' as cBdlb,'Xjb' as cTableName,'销假' as cBdlbName, cast(g.iQjbId as varchar(20))  as cbh, g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,g.iZw  From Xjb g, GetChildsZzjg('17') as  Zzjg ,Sys_userOrg U, Shpzb s  where  g.cUserCode <>'scyc18001' and s.cBdlb='20100209110900655' and g.iZw='4'and g.cUserCode=U.cUserCode and U.cZzjgdm=Zzjg.cZzjgdm and (g.iState=1 or g.iState=4)  and s.cShr in( '7') Union  select '20100209110900655' as cBdlb,'Xjb' as cTableName,'销假' as cBdlbName, cast(g.iQjbId as varchar(20))  as cbh, g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,g.iZw  From Xjb g, GetChildsZzjg('17') as  Zzjg ,Sys_userOrg U, Shpzb s  where  g.cUserCode <>'scyc18001' and s.cBdlb='20100209110900655' and g.iZw='5'and g.cUserCode=U.cUserCode and U.cZzjgdm=Zzjg.cZzjgdm and (g.iState=1 or g.iState=4)  and s.cShr in( '7') Union  select 'Jbdjb' as cBdlb,'Jbdjb' as cTableName,cBdlbName,cast(g.iAutoId as varchar(20))  as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl from Jbdjb g, Shpzb s    where  s.cBdlb='Jbdjb' and  (g.iState=1 or g.iState=4) and g.cSgzdm='17' and S.cSgzdm='17' and s.cShr in ('7') Union  select 'Qsnzjb' as cBdlb,'Qsnzjb' as cTableName,cBdlbName,cast(g.iAutoId as varchar(20))  as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl from Qsnzjb g, Shpzb s    where  s.cBdlb='Qsnzjb' and  (g.iState=1 or g.iState=4) and g.cSgzdm='17' and S.cSgzdm='17' and s.cShr in ('7') Union  select 'Gazjb' as cBdlb,'Gazjb' as cTableName,cBdlbName,cast(g.iAutoId as varchar(20))  as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl from Gazjb g, Shpzb s    where  s.cBdlb='Gazjb' and (g.iState=1 or g.iState=4) and g.cSgzdm1='17' and s.cShr in ('7') Union  select 'Xmsqb' as cBdlb,'Xmsqb' as cTableName,cBdlbName,cXmbh as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl from Xmsqb g ,  Shpzb s    where  s.cBdlb='Xmsqb' and  (g.iState=1 or g.iState=4) and g.cSgzdm='17' and S.cSgzdm='17' and s.cShr in ('7') Union  select 'Xmbg' as cBdlb,'Xmbg' as cTableName,cBdlbName,cXmbh as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl from Xmbg g ,  Shpzb s    where  s.cBdlb='Xmbg' and  (g.iState=1 or g.iState=4) and g.cSgzdm='17' and S.cSgzdm='17' and s.cShr in ('7') Union select 'Zyzxxb' as cBdlb,'Zyzxxb' as cTableName,cBdlbName,cZyzbh as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl from Zyzxxb g ,dbo.GetChildsZzjg('17') z,Shpzb s   where  s.cBdlb='Zyzxxb' and  s.cShr in ('7') and (g.iState=1 or g.iState=4) and  g.cZzjgdm=z.cZzjgdm  Union select 'Zyzsqtcb' as cBdlb,'Zyzsqtcb' as cTableName,cBdlbName,cZyzbh as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl from Zyzsqtcb g ,dbo.GetChildsZzjg('17') z,Shpzb s   where  s.cBdlb='Zyzsqtcb' and  s.cShr in ('7') and (g.iState=1 or g.iState=4) and  g.cZzjgdm=z.cZzjgdm ) Audit,UnitUser U where  Audit.cUserCode=U.cUserCode  and Audit.iSeqNo= dbo.GetAuditSeqNo(Audit.cbh,Audit.cBdlb)

解决方案 »

  1.   

    怎么换临时表啊 ,是在SQL里面建表吗?还是?
      

  2.   

    from 的括号中大概有25个select,可以将其5个一组合生成一个临时表,这样25个表的union就变成5个临时表的union了
      

  3.   

    我弄了一张临时表,在本地运行是可以的,可是为什么挂到服务器上面他说,找不到此表,select * from ##shpzb1
      

  4.   

    select * from 服务器.数据库.所有者.##shpzb1
      

  5.   

    是需要做审核表啊,所以很多表中的审核都需要查出来,就变成这样的SQL语句了。难道不好改吗?怎么弄才能优化啊
      

  6.   

    /// <summary>
            /// 获取需要审核的表单,审核配制表
            /// </summary>
            /// <param name="strZw">职务代码</param>
            /// <param name="strSgzdm">社工站代码</param>
            /// <param name="strZzjgdm">组织机构代码</param>
            /// <returns></returns>
            public DataSet GetAuditInfo(string strZw, string strSgzdm,string strZzjgdm,string strUserCode)
            {
                DataSet ds = DbHelperSQL.Query("select cMenuId,cTableName,cBdlbName,cBdlb,cTj,cRyfl,cShr  from shpzb where cTableName='Qjb'" +
                                               " select cMenuId,cTableName,cBdlbName,cBdlb,cTj,cRyfl,cShr from shpzb where cTableName='Xjb'");
                // 审核配置表,请假的配置记录
                DataTable dtQj =ds.Tables[0];
                // 审核配置表,销假的配置记录
                DataTable dtXj =ds.Tables[1];            string[] astrZw = strZw.Split(',');
                strZw = string.Empty;
                foreach (string zw in astrZw)
                {
                    strZw = strZw + "'" + zw + "',";
                }            strZw = strZw.Remove(0, 1).ToString();
                strZw = strZw.Remove(strZw.Length - 2, 2).ToString();            string strWhere = "(g.iState=1 or g.iState=4) and g.cSgzdm='" + strSgzdm + "' and S.cSgzdm='" + strSgzdm + "' and s.cShr in ('" + strZw + "')";            StringBuilder strSql = new StringBuilder();            strSql.Append("select distinct cBdlb,cTableName,cBdlbName,cbh,dSqrq,cMenuId,U.cUserName,cRyfl #shp from  ( ");            // 个案申请,根据用户的职务获取审核的表单类别
                strSql.Append("select 'Gagzsqb' as cBdlb,'Gagzsqb' as cTableName,cBdlbName,cGabh as cbh,dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl into #1 from Gagzsqb g , Shpzb s");
                strSql.Append(" where  s.cBdlb='Gagzsqb' and  " + strWhere);            strSql.Append(" Union ");
                // 个案结案
                strSql.Append(" select 'Gajazybg' as cBdlb,'Gajazybg' as cTableName,cBdlbName,cGabh as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl into #2 from Gajazybg g ,  Shpzb s  ");
                strSql.Append(" where  s.cBdlb='Gajazybg' and  " + strWhere);            strSql.Append(" Union ");
                // 小组活动申请
                strSql.Append(" select 'Xzgzsqb' as cBdlb,'Xzgzsqb' as cTableName,cBdlbName,cXzbh as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl into #3 from Xzgzsqb g ,  Shpzb s   ");
                strSql.Append(" where  s.cBdlb='Xzgzsqb' and  " + strWhere);            strSql.Append(" Union ");
                // 小组工作结案评估表
                strSql.Append(" select 'Xzgzjapgb' as cBdlb,'Xzgzjapgb' as cTableName,cBdlbName,cXzbh as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl into #4  from Xzgzjapgb g ,  Shpzb s   ");
                strSql.Append(" where  s.cBdlb='Xzgzjapgb' and  " + strWhere);            strSql.Append(" Union ");
                // 社区工作申请
                strSql.Append(" select 'Sqgzsqb' as cBdlb,'Sqgzsqb' as cTableName,cBdlbName,cSqgzbh as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl into #5  from Sqgzsqb g ,  Shpzb s   ");
                strSql.Append(" where  s.cBdlb='Sqgzsqb' and  " + strWhere);            strSql.Append(" Union ");
                // 社区工作评估报告
                strSql.Append(" select 'Sqgzpgbg' as cBdlb,'Sqgzpgbg' as cTableName,cBdlbName,cSqgzbh as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl into #6 from Sqgzpgbg g , Shpzb s   ");
                strSql.Append(" where  s.cBdlb='Sqgzpgbg' and  " + strWhere);            // 请假
                foreach (DataRow dr in dtQj.Rows)
                {
                    strSql.Append(" Union ");
                    strSql.Append(" select '" + dr["cBdlb"].ToString() + "' as cBdlb,'" + dr["cTableName"].ToString() + "' as cTableName,'" + dr["cBdlbName"].ToString() + "' as cBdlbName,");
                    strSql.Append(" cast(g.iAutoId as varchar(20))  as cbh, g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,g.iZw   ");
                    strSql.Append(" From Qjb g, GetChildsZzjg('" + strZzjgdm + "') as  Zzjg ,Sys_userOrg U, Shpzb s ");
                    strSql.Append(" where  g.cUserCode <>'"+ strUserCode +"' and s.cBdlb='" + dr["cBdlb"].ToString() + "' and g.iZw='" + dr["cRyfl"].ToString() + "'");                if (dr["cTj"].ToString() != "不限")
                    {
                        strSql.Append(" and datediff(d,g.dQjkssj,g.dQjjssj) " + dr["cTj"].ToString() + " ");
                    }                strSql.Append("and g.cUserCode=U.cUserCode and U.cZzjgdm=Zzjg.cZzjgdm ");
                    strSql.Append("and (g.iState=1 or g.iState=4)  and s.cShr in( '" + strZw + "')");
                }            // 销假
                foreach (DataRow dr in dtXj.Rows)
                {
                    strSql.Append(" Union ");
                    strSql.Append(" select '" + dr["cBdlb"].ToString() + "' as cBdlb,'" + dr["cTableName"].ToString() + "' as cTableName,'" + dr["cBdlbName"].ToString() + "' as cBdlbName,");
                    strSql.Append(" cast(g.iQjbId as varchar(20))  as cbh, g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,g.iZw ");
                    strSql.Append(" From Xjb g, GetChildsZzjg('" + strZzjgdm + "') as  Zzjg ,Sys_userOrg U, Shpzb s ");
                    strSql.Append(" where  g.cUserCode <>'" + strUserCode + "' and s.cBdlb='" + dr["cBdlb"].ToString() + "' and g.iZw='" + dr["cRyfl"].ToString() + "'");                if (dr["cTj"].ToString() != "不限")
                    {
                        strSql.Append(" and datediff(d,g.dQjkssj,g.dQjjssj) " + dr["cTj"].ToString() + " ");
                    }                strSql.Append("and g.cUserCode=U.cUserCode and U.cZzjgdm=Zzjg.cZzjgdm ");
                    strSql.Append("and (g.iState=1 or g.iState=4)  and s.cShr in( '" + strZw + "')");
                }            strSql.Append(" Union ");
                // 加班
                strSql.Append(" select 'Jbdjb' as cBdlb,'Jbdjb' as cTableName,cBdlbName,cast(g.iAutoId as varchar(20))  as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl into #7  from Jbdjb g, Shpzb s   ");
                strSql.Append(" where  s.cBdlb='Jbdjb' and  " + strWhere);            strSql.Append(" Union ");
                // 服务对象转出申请           
                strSql.Append(" select 'Qsnzjb' as cBdlb,'Qsnzjb' as cTableName,cBdlbName,cast(g.iAutoId as varchar(20))  as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl into #8  from Qsnzjb g, Shpzb s   ");
                strSql.Append(" where  s.cBdlb='Qsnzjb' and  " + strWhere);
                strSql.Append(" Union ");
                // 个案转出申请
                strSql.Append(" select 'Gazjb' as cBdlb,'Gazjb' as cTableName,cBdlbName,cast(g.iAutoId as varchar(20))  as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl into #9  from Gazjb g, Shpzb s   ");
                strSql.Append(" where  s.cBdlb='Gazjb' and (g.iState=1 or g.iState=4) and g.cSgzdm1='" + strSgzdm + "' and s.cShr in ('" + strZw + "')");
               
                strSql.Append(" Union ");
                // 项目申请
                strSql.Append(" select 'Xmsqb' as cBdlb,'Xmsqb' as cTableName,cBdlbName,cXmbh as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl into #10  from Xmsqb g ,  Shpzb s   ");
                strSql.Append(" where  s.cBdlb='Xmsqb' and  " + strWhere);            strSql.Append(" Union ");
                // 项目报告
                strSql.Append(" select 'Xmbg' as cBdlb,'Xmbg' as cTableName,cBdlbName,cXmbh as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl into #11 from Xmbg g ,  Shpzb s   ");
                strSql.Append(" where  s.cBdlb='Xmbg' and  " + strWhere);            strSql.Append(" Union ");
                // 志愿者申请登记
                strSql.Append("select 'Zyzxxb' as cBdlb,'Zyzxxb' as cTableName,cBdlbName,cZyzbh as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl into #12 ");
                strSql.Append("from Zyzxxb g ,dbo.GetChildsZzjg('" + strZzjgdm + "') z,Shpzb s   ");
                strSql.Append("where  s.cBdlb='Zyzxxb' and  s.cShr in ('" + strZw + "') and (g.iState=1 or g.iState=4) and  g.cZzjgdm=z.cZzjgdm ");
                strSql.Append(" Union ");
                // 志愿者申请退出
                strSql.Append("select 'Zyzsqtcb' as cBdlb,'Zyzsqtcb' as cTableName,cBdlbName,cZyzbh as cbh,g.dLastDate as dSqrq,s.iSeqNo,s.cMenuId,g.cUserCode,cRyfl into #13 ");
                strSql.Append("from Zyzsqtcb g ,dbo.GetChildsZzjg('" + strZzjgdm + "') z,Shpzb s   ");
                strSql.Append("where  s.cBdlb='Zyzsqtcb' and  s.cShr in ('" + strZw + "') and (g.iState=1 or g.iState=4) and  (g.cZzjgdm=z.cZzjgdm) ");            strSql.Append(") Audit,UnitUser U");
                strSql.Append(" where  Audit.cUserCode=U.cUserCode ");            //strSql.Append("  and  not exists (select 1 from Shb s where s.bOver=0 and s.cBdlb=Audit.cBdlb ");
                //strSql.Append("and s.cBdbh=Audit.cbh and (S.iSeqNo>Audit.iSeqNo or ( S.iSeqNo=Audit.iSeqNo and S.bPass=1 )))");            strSql.Append(" and Audit.iSeqNo= dbo.GetAuditSeqNo(Audit.cbh,Audit.cBdlb)");            string sql = "select * from  #shp";            return DbHelperSQL.Query(sql.ToString());
                
            }
    以上是整个方法体啊,怎么才能优化这段代码啊,拜托了
      

  7.   

    你为什么非要一次性的审核呢?
    为什么不能把相关的若干字段放到一个审核块、
    把整个大的审核分解成若干小的审核块呢?
    比如我把A表、B表和C表的几个字段先审核,
    然后再把D表和E表的几个字段再审核。
    全通过,就OK,有一个没通过就报error,不行吗?