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

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
maurix
Posts: 7
Joined: Wed 08 Oct 2008 17:48

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

Post by maurix » Mon 09 Dec 2013 18:03

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.

AndreyZ

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

Post by AndreyZ » Tue 10 Dec 2013 09:43

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.

Post Reply