[GIS] MapBasic – Updating blank rows in column with the value above

mapbasicmapinfosql

I am writing a MapBasic tool to correct some incorrect values in a set of tables. So far I have managed to pull out the values I need in a new column:

enter image description here

What I need is to update any blank rows in the OBSERVATION column with the value above it (the L*** text).

How would I go about doing this in MapBasic?

Best Answer

Something along these lines:

Dim nRowID As Integer,
    sValue As String

Fetch First From MY_TABLE
Do Until EOT(MY_TABLE)
   If MY_TABLE.OBSERVATION = "" Then
      nRowID = MY_TABLE.ROWID
      Update MY_TABLE
         Set OBSERVATION = sValue
         Where ROWID = nRowID
   Else
      sValue = MY_TABLE.OBSERVATION
   End If

   Fetch Next From MY_TABLE
Loop

Note that the loop remembers the last read value from the column OBSERVATION. This also means that the value used might not be taken from the record before – it could be a record before that in case you have multiple row without any value.

Related Question