locked
Update - how to add to a text field? RRS feed

  • Question

  • Hi all,

    I use vfp9 sp2 and winxp.

    I have a table table1 with the text field roles. I want to add an 'x' to the field for the record with id = 1:

    update table1 set roles = roles + 'x' where id = 1

    However, nothing is added.

    To change the field to 'x' works OK:

    update table1 set roles = 'x' where id = 1.

    What am I doing wrong?

    Regards,

    Jan

     

    Saturday, December 3, 2011 10:42 AM

Answers

  • Assumed roles is a C() field, eg C(10), what do you do?

    roles = roles+'x' is setting role to it's old C(10) value plus an 'x', but since that is a C(11) value the 'x' at the end is cut off.

    If you see 'text' stored within the roles field, what actually is stored in it is 'text      ', including trailing spaces. You want to add x as in 'textx', not as in 'text      x', then you need to trim:

    update table1 set roles = rtrim(roles) + 'x' where id = 1

    Bye, Olaf.

    • Proposed as answer by Pavel Celba Saturday, December 3, 2011 2:31 PM
    • Marked as answer by damezumari Saturday, December 3, 2011 5:00 PM
    Saturday, December 3, 2011 12:40 PM