PC: Dynamic Where Clause



REM ***********************************************Modification Summary******;
REM SL.No Developer     Mod. No.   Date      Changes
REM ----- -----------    ---------- ---------- -------------------------------------------

REM************************************************************************;

&str_WhereClause = "";
&str_NoAddnlClause = "N";



/* Clause for acad org */
If (LAC_CSG_RPT_AET.ACAD_ORG.Value <> " ") Then
   &str_WhereClause = " A.ACAD_ORG = '" | LAC_CSG_RPT_AET.ACAD_ORG.Value | "' ";
   &str_NoAddnlClause = "Y";
End-If;


/* Clause for Subject */
If All(LAC_CSG_RPT_AET.SUBJECT.Value) Then
   If &str_NoAddnlClause = "Y" Then
      &str_WhereClause = &str_WhereClause | " AND A.SUBJECT = '" | LAC_CSG_RPT_AET.SUBJECT.Value | "' ";
   Else
      &str_WhereClause = "  A.SUBJECT = '" | LAC_CSG_RPT_AET.SUBJECT.Value | "' ";
      &str_NoAddnlClause = "Y";
   End-If;
End-If;

/* Clause for Session */
If All(LAC_CSG_RPT_AET.SESSION_CODE.Value) Then
   If &str_NoAddnlClause = "Y" Then
      &str_WhereClause = &str_WhereClause | " AND A.SESSION_CODE = '" | LAC_CSG_RPT_AET.SESSION_CODE.Value | "' ";
   Else
      &str_WhereClause = "  A.SESSION_CODE = '" | LAC_CSG_RPT_AET.SESSION_CODE.Value | "' ";
      &str_NoAddnlClause = "Y";
   End-If;
End-If;

/* Clause for shedule print  */
If (LAC_CSG_RPT_AET.SCHEDULE_PRINT.Value = "Y") Then
   If &str_NoAddnlClause = "Y" Then
      &str_WhereClause = &str_WhereClause | " AND A.SCHEDULE_PRINT = '" | LAC_CSG_RPT_AET.SCHEDULE_PRINT.Value | "' ";
   Else
      &str_WhereClause = " A.SCHEDULE_PRINT = '" | LAC_CSG_RPT_AET.SCHEDULE_PRINT.Value | "' ";
      &str_NoAddnlClause = "Y";
   End-If;
End-If;

/* Clause for shedule print INSTR */
If (LAC_CSG_RPT_AET.SCHED_PRINT_INSTR.Value = "Y") Then
   If &str_NoAddnlClause = "Y" Then
      &str_WhereClause = &str_WhereClause | " AND B.SCHED_PRINT_INSTR(+) = '" | LAC_CSG_RPT_AET.SCHED_PRINT_INSTR.Value | "' ";
   Else
      &str_WhereClause = " B.SCHED_PRINT_INSTR(+) = '" | LAC_CSG_RPT_AET.SCHED_PRINT_INSTR.Value | "' ";
      &str_NoAddnlClause = "Y";
   End-If;
End-If;

/* Clause for CLASS STATUS */
Local string &In_List;
&In_List = "";

If LAC_CSG_RPT_AET.PRINT_CLASS_STAT_A.Value = "Y" Then
   &In_List = &In_List | "'" | "A" | "'" | ",";
End-If;


If LAC_CSG_RPT_AET.PRINT_CLASS_STAT_C.Value = "Y" Then
   &In_List = &In_List | "'" | "X" | "'" | ",";
End-If;

If LAC_CSG_RPT_AET.PRINT_CLASS_STAT_T.Value = "Y" Then
   &In_List = &In_List | "'" | "T" | "'" | ",";
End-If;

If LAC_CSG_RPT_AET.PRINT_CLASS_STAT_S.Value = "Y" Then
   &In_List = &In_List | "'" | "S" | "'" | ",";
End-If;
&In_List = RTrim(&In_List, ",");
If LAC_CSG_RPT_AET.PRINT_CLASS_STAT_A.Value = "Y" Or
      LAC_CSG_RPT_AET.PRINT_CLASS_STAT_C.Value = "Y" Or
      LAC_CSG_RPT_AET.PRINT_CLASS_STAT_T.Value = "Y" Or
      LAC_CSG_RPT_AET.PRINT_CLASS_STAT_S.Value = "Y" Then
   If &str_NoAddnlClause = "Y" Then
     
      &str_WhereClause = &str_WhereClause | " AND A.CLASS_STAT IN (" | &In_List | ")";
   Else
      &str_WhereClause = "A.CLASS_STAT IN (" | &In_List | ")";
      &str_NoAddnlClause = "Y";
   End-If;
End-If;
If &str_NoAddnlClause = "N" Then
   &str_WhereClause = "  1 = 1 ";
End-If;
LAC_CSG_RPT_AET.WHERE_CLAUSE.Value = &str_WhereClause;

Comments

Popular posts from this blog

BI Publisher: If Condition with sub-string in rtf template