private void BuildJoin(StringBuilder sb, ConnectorBase connection) { if (_ListJoin != null) { foreach (Join join in _ListJoin) { switch (join.JoinType) { case JoinType.InnerJoin: sb.Append(@" INNER JOIN "); break; case JoinType.LeftJoin: sb.Append(@" LEFT JOIN "); break; case JoinType.RightJoin: sb.Append(@" RIGHT JOIN "); break; case JoinType.LeftOuterJoin: sb.Append(@" LEFT OUTER JOIN "); break; case JoinType.RightOuterJoin: sb.Append(@" RIGHT OUTER JOIN "); break; case JoinType.FullOuterJoin: sb.Append(@" FULL OUTER JOIN "); break; } if (join.RightTableSchema != null) { if (join.RightTableSchema.DatabaseOwner.Length > 0) { sb.Append(connection.WrapFieldName(join.RightTableSchema.DatabaseOwner)); sb.Append('.'); } sb.Append(connection.WrapFieldName(join.RightTableSchema.Name)); } else { sb.Append('('); if (join.RightTableSql is Query) { sb.Append(((Query)join.RightTableSql).BuildCommand(connection)); } else { sb.Append(join.RightTableSql.ToString()); } sb.Append(')'); } sb.Append(' '); if (join.RightTableAlias != null) { sb.Append(join.RightTableAlias); } else { sb.Append(join.RightTableSchema != null ? join.RightTableSchema.Name : @""); } if (join.Pairs.Count > 1) { sb.Append(@" ON "); WhereList wl = new WhereList(); foreach (WhereList joins in join.Pairs) { wl.AddRange(joins); } wl.BuildCommand(sb, connection, this, join.RightTableSchema, join.RightTableAlias == null ? join.RightTableSchema.Name : join.RightTableAlias); } else if (join.Pairs.Count == 1) { sb.Append(@" ON "); join.Pairs[0].BuildCommand(sb, connection, this, join.RightTableSchema, join.RightTableAlias == null ? join.RightTableSchema.Name : join.RightTableAlias); } } } }