Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi
I want to automatically drop all table fields in script, which have 0 Information density (= NULL values only). How can I achieve this?
Thx a lot!
Marcel
Note that dropping a field in a table Impacts the internal field no index. Therefore you should use:
//Drop field with NULL values only, ignore fields in theExceptionFieldList
SUB DropQVFieldsWithNULLValuesOnly ( theExceptionFieldList )
FOR a = 0 TO NoOfTables() - 1
LET vTable = TableName($(a));
LET d = 0;
FOR i = 1 TO NoOfFields('$(vTable)')
LET j = i - d;
LET vField = FieldName($(j), '$(vTable)');
LET vFieldValueCount = Alt(FieldValueCount('$(vField)'), 0);
IF (vFieldValueCount <= 0 AND INDEX('$(vField)', '$(theExceptionFieldList)') <= 0) THEN
DROP FIELD [$(vField)] FROM $(vTable);
TRACE DROP FIELD [$(vField)] FROM $(vTable);
LET d = d + 1; // dropping fields impacts the internal field no.
END IF
NEXT i
NEXT a
END SUB
And call the SUB with e.g. CALL DropQVFieldsWithNULLValuesOnly ( 'Booking - not to be deleted' );
Marcel
Good catch Marcel. I created a document in community with this content, because it may help others who are looking for similar one.
Link: Remove Empty columns (All Null values) in script dynamically
Regards,
Jagan.