gdtrfb


Hi all,

I would like to copy a column that has prices (fprice) for parts in it to another column within the same table.  Then I am going to do a replace on the original column (fprice) to increase the price by a fixed amount (I know how to do that).  The table has a column that is not used for anything (by us) within the application.  It is a User Character 3 field (fcusrchr3).  I need to do this so our CFO can look back at the old pricing if need be.  Any help copying the column would be greatly appreciated.  FYI, this is in Visual Foxpro 6.

Thanks,

Erik




Re: How to copy one column to another

CetinBasoz


Assuming prices wouldn't fit in that existing field:

Alter table myTable add column oldPrice y

nFixedIncrease = 0.05 && 5% increase
select myTable
replace all oldPrice with fprice, fprice with fprice * (1+m.nFixedIncrease) && could use update sql as well






Re: How to copy one column to another

rknh_20

Try this...

use tablename
goto top
do while not EOF()
replace newfieldname with oldfieldname
skip
enddo






Re: How to copy one column to another

gdtrfb

Thank you,

This worked great. I had actually tried it before, but I was getting a data type mismatch. The post above yours by CetinBasoz made me think about the field data type. So I switched fcusrchr3 to numerical, did the replace which now worked, and then changed fusrchr3 back to Character. Thanks for keeping me thinking.

Erik





Re: How to copy one column to another

CetinBasoz

FYI scope clause "ALL" that is found in many commands like replace,delete etc are an easy way of saying do for all records. IOW:

go top
do while !eof()
replace x with y
skip
enddo

Could be rewritten as:

replace ALL x with y

and operates faster. You could even add in cAliasName and remove the need to be in that workarea. Try to stay away from do while ... enddo constructs if there is an alternative (and generally there is).