Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copying data from one field to another 2

Status
Not open for further replies.

croakyfrog

Technical User
Dec 4, 2001
51
GB
hi

i have a table with 3 fields - two of them need to be populated with zero values and the other one needs to be populated with a value from another field within the table.

i really havent a clue how to go about this as ive only been using foxpro 2.5 for a few months and then only in a basic way.

can anyone help me?
 
Simple try
replace all field1 with 0, field2 with 0, field3 with fieldx
 
would i be able to do this for fields between date ranges?
 
Assuming the date range you want to use is contained in a
DATE type field, you can use something like:
REPLACE ALL ;
field1 with 0, field2 with 0, field3 with fieldx ;
FOR BETWEEN(date_field, CTOD('12/01/2001'), CTOD('12/31/2001'))

Dave S.
 
how do i know if they are datetime fields?

also - do i run this as a query, if so how or can i run it from the little window ie the one that i usually type in use filename, brow etc.?

sorry if i sound a bit thick im just a bit *new*

thanks for replyng by the way i really appreciate it, i hope you have an exellent christmas :)
 
Croakyfrog,
The REPLACE statment will work directly against the table you have open in the current "Work" area. I STRONGLY recommend you make a copy of the table before you perform "REPLACE" opperations on it, in the event you do not get the results you are expecting. So, to answer your question, yes, you enter the REPLACE statment directly into the "Little Window" (also known as the COMMAND window, in Fox Speak). To be safe do something like this:

SELECT 0
USE C:\DATA\MYDBF.DBF && where path and file are your table
COPY TO OLDDBF WITH PRODUCTION
*
* What we've done so far, is copy the contents of the
* existing DBF to a new file called "OLDDBF.DBF", and
* we have included any existing Indexes on that file,
* with the "WITH PRODUCTION" statement, so we can quckly
* recover if we have a problem later, by simply renaming
* OLDDBF.* to MYDBF.*
*
Next issue your replace

REPLACE ALL FIELD1 WITH 0
REPLACE ALL FIELD2 WITH 0
REPLACE ALL FIELD3 WITH OTHERFIELD WHERE DATEFIELD >= {12/01/2001} AND DATEFIELD <= {12/31/2001}
*
* The last replace statement is just a slightly different
* way than DSummZZZ suggested, you can you his syntax or
* mine. I think if you are new, my replaces might be a
* little clearer to you, but his are more efficient.
*
Now, to answer your last question, how can you tell if they are DATETIME fields... 2 parts to that. First, Fox 2.x does not support DATETIME fields, only DATE fields. You can tell a couple of ways. Probably the easiest is to open your table in a work area, (as I showed above), and in the Command Window enter:

? TYPE(MYDBF.DATEFIELD)

Where MYDBF is the name of your table, and DATEFIELD is the name of the field you want to know the type of. if this displays a &quot;D&quot; on your Fox desktop, it is DATE, if it displays a &quot;C&quot; then it is a character. If it is a character, all is not lost, you can still use something like DSumm suggests with CTOD, which is Character to Date before performing the opperation.

Good luck!

Thanks,
-Scott

s-) Please let me know if this has helped s-)
 
thank you - you all gave me a really useful insight into this problem resulting in me gaining several brownie points which of course i must pass on to you.

i dont suppose any of you know of any sites that contain information like this? the problem with old systems really is finding documentation, training manuals etc.

you have saved me possibly days of work and i really do hope you all have the best christmas ever and that next year brings you everything youve ever wished for.

;)
 
Well, this is one of the best sites I have seen. Be sure and look at the FAQ's, and use the search utitlity on this site as there are a lot of questions that can be answered that way. Another is the Universal Thread. ( There are a lot of gurus that frequest that site. The Virtual FoxPro User Group is another. (Of course Fox does come with on-line documentaion, I shudder when I say that, but I have been programming in Fox/VFP for about 12 years and I still refer to it because well, I can't memorize everything.

Dave S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top