Return to the SQL Tips
Embedded SQL - Filtering data for a subfile as an example
Let?s say there are 3 fields for filtering on. SelFld1a, etc? will be work fields. ScreenFlda, etc? will be the fields on the screen the user enters the filter data into. C Eval SelFld1a=*loval C Eval SelFld1b=*hival C Eval SelFld2a=*loval C Eval SelFld2b=*hival C Eval SelFld3a=*loval C Eval SelFld3b=*hival * C If ScreenFlda <> *Blanks C Eval SelFld1a=ScreenFlda C Eval SelFld1b=ScreenFlda C Endif C If ScreenFldb <> *Blanks C Eval SelFld2a=ScreenFldb C Eval SelFld2b=ScreenFldb C Endif C If ScreenFldc <> *zero C Eval SelFld3a=ScreenFldc C Eval SelFld3b=ScreenFldc C Endif The one SQL statement below will work for all scenarios. If a value is entered on the screen you will only select that value for the column. The fields not entered will pull all data for that column (field). C/EXEC SQL C+ Select Field1, Field2, Field3 C+ from TABLEA C+ where Field1 between :SelFld1a and :SelFld1b C+ and Field2 between :SelFld2a and :SelFld2b C+ and Field3 between :SelFld3a and :SelFld3b C/END-EXEC
[report a broken link by clicking here]