PowerBuilder Function Distinct Values gf_distinctvalues
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : gf_distinctvalues // Argument Name : as_table, Arg Type : String, Pass By : Value // as_table_dddw, Arg Type : String, Pass By : Value // as_column, Arg Type : String, Pass By : Value // as_dispcolumn, Arg Type : String, Pass By : Value // as_values[], Arg Type : String, Pass By : Reference // as_dispvalues[], Arg Type : String, Pass By : Reference // Return Type : (None) /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Get the distinct values from the database // // Arguments: // as_table: a SQL table name // as_column: a database column name in passed SQL table // as_values: string array, passed by reference to hold the returned values /////////////////////////////////////////////////////////////////////////////////////////////////////////////// Long ll_rc String ls_sqlstatement String ls_value String ls_dispvalue String ls_name // Build the SQL Select statement ls_sqlstatement = "SELECT DISTINCT " + as_column + "," +as_dispcolumn+ " FROM " + as_table + & "," + as_table_dddw + " WHERE " + as_column +" = "+ as_table_dddw + Mid(as_column,Pos(as_column,".")) // Execute the SQL Prepare sqlsa From :ls_sqlstatement; Describe sqlsa Into sqlda; Declare c_values_cursor Dynamic Cursor For sqlsa; Open Dynamic c_values_cursor Using Descriptor sqlda; Fetch c_values_cursor Using Descriptor sqlda; ll_rc = sqlca.SQLCode // Retrieve the distinct values and add them to the array Do While sqlca.SQLCode = 0 Choose Case sqlda.OutParmType[1] Case TypeString! ls_value = GetDynamicString (sqlda, 1) Case TypeDate! ls_value = String (GetDynamicDate (sqlda, 1)) Case TypeTime! ls_value = String (GetDynamicTime (sqlda, 1)) Case TypeDateTime! ls_value = String (GetDynamicDateTime (sqlda, 1)) Case Else ls_value = String (GetDynamicNumber (sqlda, 1)) End Choose Choose Case sqlda.OutParmType[2] Case TypeString! ls_dispvalue = GetDynamicString (sqlda, 2) Case TypeDate! ls_dispvalue = String (GetDynamicDate (sqlda, 2)) Case TypeTime! ls_dispvalue = String (GetDynamicTime (sqlda, 2)) Case TypeDateTime! ls_dispvalue = String (GetDynamicDateTime (sqlda, 2)) Case Else ls_dispvalue = String (GetDynamicNumber (sqlda, 2)) End Choose as_values[UpperBound(as_values)+1] = ls_value as_dispvalues[UpperBound(as_dispvalues)+1] = ls_dispvalue Fetch c_values_cursor Using Descriptor sqlda; ll_rc = sqlca.SQLCode Loop Close c_values_cursor; |
Good Luck!