Tilføj blot en test på sysdate og tildelingskolonnerne
var sql = "SELECT " +
"SPØRGSMÅL_ID, " +
"KARAKTER, " +
"COUNT(*) AS COUNT " +
"FROM " +
"KS_DRIFT.KT_KARAKTER kara " +
"LEFT JOIN " +
"KS_DRIFT.KT_BESVARELSE besv ON kara.BESVARELSE_ID = besv.EKSTERN_ID AND kara.TYPE = besv.TYPE " +
"LEFT JOIN " +
"KS_DRIFT.V_AGENT_ALLOCATION age ON " + (queryParams.JoinOnFirstAgent ? "FØRSTE_AGENT" : "SIDSTE_AGENT") + " = age.AGENT_INITIALS AND TIDSPUNKT >= ALLOCATION_START AND TIDSPUNKT < ALLOCATION_END + 1 " +
"and sysdate BETWEEN ALLOCATION_START AND ALLOCATION_END " +
"WHERE TIDSPUNKT >= to_date(" +
OracleConversion.ToOracleDate(queryParams.Interval.Lower) +
",'YYYY-MM-DD') AND TIDSPUNKT < to_date(" +
OracleConversion.ToOracleDate(queryParams.Interval.Upper) +
",'YYYY-MM-DD') + 1 AND " +
"SPØRGSMÅL_ID = " + queryParams.QuestionId +
(!queryParams.IncludeCDNs.IsNullOrEmpty() ? "AND CDN IN (" + queryParams.IncludeCDNs.ToDelimitedString(", ") + ") " : "") +
(!queryParams.ExcludeCDNs.IsNullOrEmpty() ? "AND CDN NOT IN (" + queryParams.ExcludeCDNs.ToDelimitedString(", ") + ") " : "") +
(!queryParams.AgentIds.IsNullOrEmpty() ? " AND AGENT_ID IN (" + queryParams.AgentIds.ToDelimitedString(", ") + ") " : "") +
(!queryParams.TeamIds.IsNullOrEmpty() ? " AND TEAM_ID IN (" + queryParams.TeamIds.ToDelimitedString(", ") + ") " : "") +
"GROUP BY " +
"SPØRGSMÅL_ID, " +
"KARAKTER";