private string UpdateSql() { StringBuilder sb = new StringBuilder(); UpdateTable BaseTable = this.BaseTable() as UpdateTable; string declare = ""; string set = ""; string outputSelect = ""; SqlBuilder tb = this.TopBuilder; foreach (ParameterField field in BaseTable.FieldList.OfType <ParameterField>()) { tb.AddDeclaration(field.ParameterName, field.DeclareParameter()); set += field.SetParameter() + "\r\n"; } if (BaseTable.Output != null && BaseTable.Output.ParameterTable.FieldList.Count > 0) { tb.AddDeclaration(BaseTable.Output.ParameterName, BaseTable.Output.DeclareParameter()); outputSelect += BaseTable.Output.SetParameter() + "\r\n"; } sb.AppendLine(declare); sb.AppendLine(set); sb.AppendFormat("UPDATE {0}\r\n", BaseTable.Name); sb.AppendFormat(" SET {0}\r\n", BaseTable.ToSql()); if (BaseTable.Output != null && BaseTable.Output.ParameterTable.FieldList.Count > 0) { sb.AppendFormat("OUTPUT {0}\r\n", BaseTable.Output.ToSql()); } sb.AppendFormat(" FROM {0}\r\n", BaseTable.ReferenceName); foreach (Join j in JoinConditions) { sb.AppendFormat("{0}\r\n", j.ToSql()); } string where = WhereConditions.ToSql(); if (!string.IsNullOrEmpty(where)) { sb.AppendFormat("WHERE {0}\r\n", where); } if (!string.IsNullOrEmpty(outputSelect)) { sb.AppendLine(outputSelect); } return(sb.ToString()); }