Page 1 of 1

Keeping existing field value if no parameter is specified for that field

Posted: Mon 09 Dec 2013 18:03
by maurix
I have a query with an SQLUpdate text with some parameters such as:

UPDATE SomeQuery
SET
Field1 = :Param1 , Field2 = :Param2 , Field3 = :Param3
WHERE
ID = :Old_ID

Is there a way to keep the existing field value if no param is specified for that field?

In other words, if I wrote:

Query.ParamByName('Param1').AsInteger := 0;
Query.ParamByName('Param2').AsInteger := 0;
{ Note that Param3 is not specified in the update query though it's defined in the SQLupdate text}
Query.ParamByName('Old_ID').AsInteger := AId;
Query.Execute;

I would like that Field3 could keep its current value without the need to specify it by code.

Thanks.

Re: Keeping existing field value if no parameter is specified for that field

Posted: Tue 10 Dec 2013 09:43
by AndreyZ
You can solve this problem in two ways:
- create SQLUpdate dynamically for needed fields only;
- use your query and pass the current value of the Field3 field to the Param3 parameter.