博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
DB2数据库用 With语句分隔字符
阅读量:6113 次
发布时间:2019-06-21

本文共 5657 字,大约阅读时间需要 18 分钟。

SELECT T1.REPAIRNO,       T1.UNDERTAKER10,       T3.FULLNAME          AS RECEIVERNAME,       T1.WALKDISTANCE,       T1.STATUSCODEDATE10  AS RECEIVETIME,       t8.REPAIRTYPE,       T5.DELIVEREDDATE,       CASE             WHEN T2.REPAIRNO IS NULL THEN '否'            ELSE '是'       END                     ISINSURANCE,       T2.FIXEDDATE,       T4.FULLNAME          AS CLAIMSNNAME,       T2.TotalFeeFROM   RT_REPAIR T1       LEFT JOIN RT_INSURANCECLAIMS T2            ON  T1.REPAIRNO = T2.REPAIRNO            AND T1.FRAMENO = T2.FRAMENO       LEFT JOIN CM_STAFF T3            ON  T1.UNDERTAKER10 = T3.STAFFPKID       LEFT JOIN CM_STAFF T4            ON  T2.ClaimsID = T4.STAFFPKID       LEFT JOIN RT_REPAIRPROCESS T5            ON  T1.REPAIRNO = T5.REPAIRNO       LEFT JOIN RT_CUSTOMERWISH T6            ON  T1.REPAIRNO = T6.REPAIRNO       LEFT JOIN RT_WORKCONTENT T7            ON  T6.REPAIRNO = T7.REPAIRNO            AND T6.WISHID = T7.WISHID       LEFT JOIN RM_RepairType t8            ON  t7.RepairTypeCode = t8.repairtypecodeWHERE  T1.FRAMENO = 'LHGRB186982000004'       AND STATUSCODE = '99'ORDER BY       REPAIRNO                DESC

 

     public DataSet GetCustomerSolicitRepairHisByFrameNo(string aFrameNo)        {            StringBuilder sql = new StringBuilder();            sql.Append(" SELECT T1.REPAIRNO, ");            sql.Append(" T1.UNDERTAKER10, ");            sql.Append(" T3.FULLNAME          AS RECEIVERNAME, ");            sql.Append(" T1.WALKDISTANCE, ");            sql.Append(" T1.STATUSCODEDATE10  AS RECEIVETIME, ");            sql.Append(" T8.REPAIRTYPE, ");            sql.Append(" T5.DELIVEREDDATE, ");            sql.Append(" CASE  ");            sql.Append(" WHEN T2.REPAIRNO IS NULL THEN '否' ");            sql.Append(" ELSE '是' ");            sql.Append(" END                     ISINSURANCE, ");            sql.Append(" T2.FIXEDDATE, ");            sql.Append(" T4.FULLNAME          AS CLAIMSNNAME, ");            sql.Append(" T2.TOTALFEE ");            sql.Append(" FROM   RT_REPAIR T1 ");            sql.Append(" LEFT JOIN RT_INSURANCECLAIMS T2 ");            sql.Append(" ON  T1.REPAIRNO = T2.REPAIRNO ");            sql.Append(" AND T1.FRAMENO = T2.FRAMENO ");            sql.Append(" LEFT JOIN CM_STAFF T3 ");            sql.Append(" ON  T1.UNDERTAKER10 = T3.STAFFPKID ");            sql.Append(" LEFT JOIN CM_STAFF T4 ");            sql.Append(" ON  T2.ClaimsID = T4.STAFFPKID ");            sql.Append(" LEFT JOIN RT_REPAIRPROCESS T5 ");            sql.Append(" ON  T1.REPAIRNO = T5.REPAIRNO ");            sql.Append(" LEFT JOIN RT_CUSTOMERWISH T6 ");            sql.Append(" ON  T1.REPAIRNO = T6.REPAIRNO ");            sql.Append(" LEFT JOIN RT_WORKCONTENT T7 ");            sql.Append(" ON  T6.REPAIRNO = T7.REPAIRNO ");            sql.Append(" AND T6.WISHID = T7.WISHID ");            sql.Append(" LEFT JOIN RM_REPAIRTYPE T8 ");            sql.Append(" ON  T7.REPAIRTYPECODE = T8.REPAIRTYPECODE ");            sql.Append(" WHERE  T1.FRAMENO = '" + aFrameNo + "' ");            sql.Append(" AND STATUSCODE = '99' ");            sql.Append(" ORDER BY ");            sql.Append(" REPAIRNO DESC ");            DataSet ds = new DataSet();            FillDataSet(sql.ToString(), ds, new string[] { "Tmp_RepairHis" });            //            string repairNo = string.Empty;            string repairType = string.Empty;            DataSet cloneDS = new DataSet();            cloneDS.Merge(ds);            cloneDS.Tables["Tmp_RepairHis"].Clear();            var cloneRow = cloneDS.Tables["Tmp_RepairHis"].NewRow();            DataRow addRow = null;            if (ds.Tables["Tmp_RepairHis"].Rows.Count == 0)            {                return cloneDS;            }            foreach (DataRow row in ds.Tables["Tmp_RepairHis"].Rows)            {                if (string.IsNullOrEmpty(repairNo))                {                    repairNo = row["REPAIRNO"].ToString();                    repairType = row["REPAIRTYPE"].ToString();                }                else if (repairNo == row["REPAIRNO"].ToString())                {                    if (row["REPAIRTYPE"] != null && row["REPAIRTYPE"] != DBNull.Value)                    {                        repairType = repairType + "," + row["REPAIRTYPE"].ToString();                    }                }                else                {                    AddNewCloneRow(addRow, cloneRow, repairNo, repairType, cloneDS);                    cloneRow = cloneDS.Tables["Tmp_RepairHis"].NewRow();                    repairNo = row["REPAIRNO"].ToString();                    repairType = row["REPAIRTYPE"].ToString();                }                addRow = row;            }            AddNewCloneRow(addRow, cloneRow, repairNo, repairType, cloneDS);            cloneDS.AcceptChanges();            return cloneDS;        }

 

     private static void AddNewCloneRow(DataRow row, DataRow cloneRow, string repairNo, string repairType, DataSet cloneDS)        {            cloneRow["REPAIRNO"] = repairNo;            cloneRow["REPAIRTYPE"] = repairType;            //补充完整其他的数据行            cloneRow["UNDERTAKER10"] = row["UNDERTAKER10"];            cloneRow["RECEIVERNAME"] = row["RECEIVERNAME"];            cloneRow["WALKDISTANCE"] = row["WALKDISTANCE"];            cloneRow["RECEIVETIME"] = row["RECEIVETIME"];            cloneRow["DELIVEREDDATE"] = row["DELIVEREDDATE"];            cloneRow["ISINSURANCE"] = row["ISINSURANCE"];            cloneRow["FIXEDDATE"] = row["FIXEDDATE"];            cloneRow["CLAIMSNNAME"] = row["CLAIMSNNAME"];            cloneRow["TOTALFEE"] = row["TOTALFEE"];            cloneDS.Tables["Tmp_RepairHis"].Rows.Add(cloneRow);        }

 

转载地址:http://mzcka.baihongyu.com/

你可能感兴趣的文章
好记性不如烂笔杆-android学习笔记<十六> switcher和gallery
查看>>
JAVA GC
查看>>
codeforce 599B Spongebob and Joke
查看>>
3springboot:springboot配置文件(外部配置加载顺序、自动配置原理,@Conditional)
查看>>
9、Dubbo-配置(4)
查看>>
前端第七天
查看>>
BZOJ 2190[SDOI2008]仪仗队
查看>>
图解SSH原理及两种登录方法
查看>>
[转载] 七龙珠第一部——第058话 魔境圣地
查看>>
【总结整理】JQuery基础学习---样式篇
查看>>
查询个人站点的文章、分类和标签查询
查看>>
基础知识:数字、字符串、列表 的类型及内置方法
查看>>
JSP的隐式对象
查看>>
P127、面试题20:顺时针打印矩阵
查看>>
JS图片跟着鼠标跑效果
查看>>
[SCOI2005][BZOJ 1084]最大子矩阵
查看>>
学习笔记之Data Visualization
查看>>
Leetcode 3. Longest Substring Without Repeating Characters
查看>>
【FJOI2015】金币换位问题
查看>>
数学之美系列二十 -- 自然语言处理的教父 马库斯
查看>>