Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Search the table
Message
 
 
To
13/05/2010 11:45:35
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01464420
Message ID:
01464423
Views:
46
>Dear All,
>I have a table with mainly numerical fields, how I can scan or search all fields for a certain number for example
>in different field I have the number lets say 6 and whenever I found this number I want to replace it with 4.
>if there is a way to do it and hope I explain it properly
>thank's a lot for your help
>Best for now

You can create a replace or update command as a text using afields if there are too many numerical fields and you don't want to list each of them.

example:
use myTable
local array laFields[1]

local lnI, lnFields, lcSQL, lcWhere, lcSet

lnFields = aFields(laFields)
store '' to lcWhere, lcSet 

for lnI = 1 to lnFields
    lf laFields[m.lnI,2] = 'N' 
 
           lcWhere = m.lcWhere + ' OR ' + laFields[m.lnI,1] + ' = 6'
           lcSet = m.lcSet + ', '  +  laFields[m.lnI,1]  + ;
                                          ' =  IIF(' + laFields[m.lnI,1]  +' = 6,4,'  + laFields[m.lnI,1]  + ')' && Keep the original value if not 6
    endif
next

if not empty(m.lcWhere)
      lcSQL = 'UPDATE myTable SET ' + stuff(m.lcSet,1,1,'') + ' WHERE ' + stuff(m.lcWhere,1,4,'')
endif

? m.lcSQL && to verify

&lcSQL
from the top of my head.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform