DB2数据库用 With语句分隔字符
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.TotalFee FROM 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.repairtypecode WHERE 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); }