hello, today I'm afflicted with a problem I'm finding hard to grasp and i hope that the more expert will be able to guide me.
basically i need to pull out data from a database and based on comparisons update fields in the db. in principle it sounds simple, but I'm struggling with the code and possibly the logic...
if it was for a few rows i thought that i could execute the query and pas the values to an array, then manipulate the array, however for thousands of columns this might not be the most efficient way (please argue against this if i'm wrong!)
a different way is to pull out values in chunks of rows, but if you look at the example below i don't have any way of checking in advance how many rows contain invalid chars.
here is an example myTable containing:
Field1, Field2, Field3, Field4 ....
100, abc, 4
100, -, 3
105, -, 5
105, -, 5
105, def, 3
101, fgh, 4
101, -, 4
....etc.
what i thought would be more efficient is to take one row at a time and compare the content with the one above and the one below (or row+i if the value returned is still invalid), but have no clue how to keep the loop clean.
here is my pseudo-code:
- create connection,
- execute query to get no of rows (i)
start loop
- execute query for row i,
get row
i.field1
get row
i.field2
if row
i.field2 = '-' then
get row
i.field1
if row
i.field1 = row
i-1.field1 then
row
i.field2=row
i-1.field2
elseif row
i.field1 = row
i+1.field1 then
row
i.field2=row
i+1.field2
else
loop until find a valid entry and use
row
i+x.field2
end if
i also need a count of the consecutive
row
i.field1 which are equal
i hope that somebody can suggest a good solution and thank you for your help! thanks