1 (edited by borisavljevic 2021-02-24 05:33:00)

Topic: [Solved] Delete only specified field from db table

Hi all,

Example: there is table emplyees with fields first_name and last_name in it. Is it possible on button click (with script) to delete only specified last_name but first_name needs to stay (i dont't want to delete whole row - record). Basically what I need is to delete only last name of specified person on button click. I tried something like this but it doesn't work:

SQLExecute('DELETE from employees WHERE last_name.id =' +Form1.tablegrid1.sqlvalue);


SQLExecute('DELETE last_name from emplyees WHERE last_name.id =' +Form1.tablegrid1.sqlvalue);

Is it possible and if it is, all I need is syntax.

Thanks in advance,
Vladimir

Re: [Solved] Delete only specified field from db table

Hi Vladimir,
Instead of using 'delete', you can use 'update' and replace the last_name either with spaces or set last_name = null.
Please have a look at the attachment.
Derek.

Post's attachments

Attachment icon vladimir.zip 340.7 kb, 7 downloads since 2021-02-23 

3 (edited by borisavljevic 2021-02-23 14:03:05)

Re: [Solved] Delete only specified field from db table

Hi Derek,

It works nice with TEXT field, but I tried with FILE field and it doesn't work in that case. In my FILE field is stored only link to copied file (files are stored in folder using CopyTo). I just want do delete that link after I remove file from folder. I'm doing something wrong?

Thanks Derek

Re: [Solved] Delete only specified field from db table

Problem solved.

sqlexecute('update emplyees set last_name_filename = null where id =' + Form1.tablegrid1.sqlvalue);

Derek, thank you for your time, you helped me a lot.

5 (edited by derek 2021-02-23 18:41:03)

Re: [Solved] Delete only specified field from db table

Hi Vladimir,
Yes, the syntax is the same for any field so I suspected that you just didn't have the correct field name for your linked file - it's always the fieldname you specify in your schema and then add   _filename.
Looking at your original question, I wondered if a more general purpose utility might be better (see attachment) - select the field you want to change and the value you want to change it to (or leave it blank if you want to clear the existing field value), then select the relevant row in the tablegrid and click the 'GO' button.  If nothing else, it's quite a quick way of correcting data.
Derek.

Post's attachments

Attachment icon vladimir.zip 350.4 kb, 14 downloads since 2021-02-23