src/main/java/de/cimt/talendcomp/exasol/EXASCDHelper.java
String createSCD2Statement1(String source, String target) {
		StringBuilder sb = new StringBuilder();
		sb.append("merge into " + source + " ta using (\n");
		sb.append("SELECT t.* FROM " + source + " s\n");
		sb.append("JOIN " + target + " t USING (\n");
		sb.append(getCslSourceString(true, false, false, false, false) + ")\n");
		sb.append("WHERE t." + validTimePeriodEndColumn + "=" + scdEndDateStr);
		sb.append(" AND (" + getCompareColumnsClause("s", "t", "scd2") + ")");
		sb.append(") sr\n");
		sb.append("on " + getKeyClause("sr", "ta") + "\n");
		sb.append("when matched then update set ta." + statusInTempTableColumn + "='CHANGED'");
		if (useVersion) {
			sb.append(", ta." + versionColumn + "=sr." + versionColumn);
		}
		sb.append(", ta." + validTimePeriodEndColumn + "=sr." + validTimePeriodEndColumn + "\n");
		// new condition for outdated updates
		sb.append("where ta." + validTimePeriodStartColumn + " > sr." + validTimePeriodStartColumn);

		String sql = sb.toString();
		if (debug) {
			System.out.println("-- createSCD2Statement1");
			System.out.println(sql + ";");
		}
		return sql;
	}
/*
	 * SCD2 STEP 1a) Mark all changed entries in STAGE
	 */
SCD2 STEP 1a) Mark all changed entries in STAGE
SCD2 STEP 1a ) Mark all changed entries in STAGE
String createSCD2Statement1(String source, String target) {
		StringBuilder sb = new StringBuilder();
		sb.append("merge into " + source + " ta using (\n");
		sb.append("SELECT t.* FROM " + source + " s\n");
		sb.append("JOIN " + target + " t USING (\n");
		sb.append(getCslSourceString(true, false, false, false, false) + ")\n");
		sb.append("WHERE t." + validTimePeriodEndColumn + "=" + scdEndDateStr);
		sb.append(" AND (" + getCompareColumnsClause("s", "t", "scd2") + ")");
		sb.append(") sr\n");
		sb.append("on " + getKeyClause("sr", "ta") + "\n");
		sb.append("when matched then update set ta." + statusInTempTableColumn + "='CHANGED'");
		if (useVersion) {
			sb.append(", ta." + versionColumn + "=sr." + versionColumn);
		}
		sb.append(", ta." + validTimePeriodEndColumn + "=sr." + validTimePeriodEndColumn + "\n");
		sb.append("where ta." + validTimePeriodStartColumn + " > sr." + validTimePeriodStartColumn);
		String sql = sb.toString();
		if (debug) {
			System.out.println("-- createSCD2Statement1");
			System.out.println(sql + ";");
		}
		return sql;
	}
String createSCD2Statement1 ( String source , String target ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "merge into " + source + " ta using (\n" ) ; sb . append ( "SELECT t.* FROM " + source + " s\n" ) ; sb . append ( "JOIN " + target + " t USING (\n" ) ; sb . append ( getCslSourceString ( true , false , false , false , false ) + ")\n" ) ; sb . append ( "WHERE t." + validTimePeriodEndColumn + "=" + scdEndDateStr ) ; sb . append ( " AND (" + getCompareColumnsClause ( "s" , "t" , "scd2" ) + ")" ) ; sb . append ( ") sr\n" ) ; sb . append ( "on " + getKeyClause ( "sr" , "ta" ) + "\n" ) ; sb . append ( "when matched then update set ta." + statusInTempTableColumn + "='CHANGED'" ) ; if ( useVersion ) { sb . append ( ", ta." + versionColumn + "=sr." + versionColumn ) ; } sb . append ( ", ta." + validTimePeriodEndColumn + "=sr." + validTimePeriodEndColumn + "\n" ) ; sb . append ( "where ta." + validTimePeriodStartColumn + " > sr." + validTimePeriodStartColumn ) ; String sql = sb . toString ( ) ; if ( debug ) { System . out . println ( "-- createSCD2Statement1" ) ; System . out . println ( sql + ";" ) ; } return sql ; }
SCD2 STEP 1a) Mark all changed entries in STAGE
SCD2 STEP 1a ) Mark all changed entries in STAGE
// new condition for outdated updates