Discussion:
change a field value
(too old to reply)
Helen123
2004-09-28 16:29:02 UTC
Permalink
I have a table with three fields, they are "aminchar","sortorder" and
"specialwt". The field "specialwt"'s value was empty. Now i want to change
its value based on the "aminchar" and "sortorder"'s value. I did the
following code:
specialwtvalue=str(10-Len(aminchar))
INSERT INTO sortorde (specialwt) VALUES ([specialwtvalue])
=TABLEUPDATE(.T.,.F., 'sortorde')

The specialwtvalue is "7" or "8", but it only accept "specialwtvalue" like a
string, not accept its value in second sentence "INSERT INTO....
VALUE([specialwtvalue]). I don't know how to pass the value of specialwtvalue
to it. Any suggestion, thanks!
Rick Bean
2004-09-28 18:52:40 UTC
Permalink
Helen,
In VFP, the brackets ([]) are an alternative to quotes (" or ') for delineating a string. So [ABC] is the same as "ABC" or 'ABC'. It isn't the same as Access or SQL Server that uses []'s to signify a field name. Try:
specialwtvalue=str(10-Len(aminchar))
INSERT INTO sortorde (specialwt) VALUES (specialwtvalue)
=TABLEUPDATE(.T.,.F., 'sortorde')

As long specialwt is a character field of 10 of more characters this will work. If it is smaller, you may want to use the optional length on the STR() function or use the transform() function. e.g. For 5 characters:
specialwtvalue=str(10-Len(aminchar), 5)
specialwtvalue=transform(10-Len(aminchar), "99999")

Rick
Post by Helen123
I have a table with three fields, they are "aminchar","sortorder" and
"specialwt". The field "specialwt"'s value was empty. Now i want to change
its value based on the "aminchar" and "sortorder"'s value. I did the
specialwtvalue=str(10-Len(aminchar))
INSERT INTO sortorde (specialwt) VALUES ([specialwtvalue])
=TABLEUPDATE(.T.,.F., 'sortorde')
The specialwtvalue is "7" or "8", but it only accept "specialwtvalue" like a
string, not accept its value in second sentence "INSERT INTO....
VALUE([specialwtvalue]). I don't know how to pass the value of specialwtvalue
to it. Any suggestion, thanks!
Jack Jackson
2004-09-29 04:57:11 UTC
Permalink
[specialwtvalue] is the same as "specialwtvalue" - it is a text
string, not a variable. I think you want to remove the brackets:
INSERT INTO sortorde (specialwt) VALUES (specialwtvalue)

You say you want to change the value of specialwt. However, your code
inserts a new record, it doesn't modify an existing record. Which do
you want to do?

On Tue, 28 Sep 2004 09:29:02 -0700, "Helen123"
Post by Helen123
I have a table with three fields, they are "aminchar","sortorder" and
"specialwt". The field "specialwt"'s value was empty. Now i want to change
its value based on the "aminchar" and "sortorder"'s value. I did the
specialwtvalue=str(10-Len(aminchar))
INSERT INTO sortorde (specialwt) VALUES ([specialwtvalue])
=TABLEUPDATE(.T.,.F., 'sortorde')
The specialwtvalue is "7" or "8", but it only accept "specialwtvalue" like a
string, not accept its value in second sentence "INSERT INTO....
VALUE([specialwtvalue]). I don't know how to pass the value of specialwtvalue
to it. Any suggestion, thanks!
Cindy Winegarden
2004-10-02 00:55:29 UTC
Permalink
Hi Helen,

The others have told you how to do what you want to do. I'd like to point
out that what you're doing is basing a field value on the values in other
fields, which is not the best data design (not "normalized") since you can
change the first two fields later and my not have always updated the derived
field. That being said, there are always times when "denormalized" data is
really what works the best, and of course you may be working with a data
design that is already "set in stone."

A common use for denormalized data is the temporary cursors you build for
reports.
--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
Post by Helen123
I have a table with three fields, they are "aminchar","sortorder" and
"specialwt". The field "specialwt"'s value was empty. Now i want to change
its value based on the "aminchar" and "sortorder"'s value. ....
Loading...