FUNCTION ChooseAllFields(ctableName) LOCAL ret_val, fl_notused, num_fields, fld_name, i ret_val = "" IF .NOT. USED(ctableName) TRY USE (ctableName) IN 0 SHARED && The table is opened in another alias CATCH USE (ctableName) IN 0 ALIAS TempAlias SHARED && The table is opened in another alias ctableName = "TempAlias" ENDTRY fl_notused = .t. ENDIF ** 1 way ********************************************** num_fields = AFIELDS(aFld , ctableName) FOR i = 1 TO num_fields ret_val = ret_val + IIF(i==1,"",",") + aFld[i,1] NEXT ********************************************************* *** 2 way *********************************************** FOR i = 1 TO FCOUNT(ctableName) ret_val = ret_val + IIF(i==1,"",",") + FIELDS(i,ctableName) NEXT ********************************************************* IF fl_notused USE IN (ctableName) ENDIF RETURN ret_val * and you can use it: c_select = "SELECT "+ChooseAllFields("MyTable") +" FROM MyTable ...." &c_selectHTH