Page 1 of 1

Problem writing field using alias (MSQuery)

Posted: Mon 06 Oct 2014 19:05
by danilo.abranches
Hello,

When i put a query in Msquery with a field using alias, it is not written.

Example:

Code: Select all

select upper(field) as field from table
Delphi:

Code: Select all

msQuery.Open;
msQuery.First;
msQuery.Edit;
msQuerycampo.AsString := 'test';
msQuery.Post;
Is that a problem? Know any solution?

Note: I'm replacing the use of TClientDataset by TMsquery

Re: Problem writing field using alias (MSQuery)

Posted: Tue 14 Oct 2014 13:21
by azyk
To generate an UPDATE SQL query, we use meta-information about a database object, that each field belongs to. For your SQL query, SQL Server doesn't return the name of the table containing the field. Therefore we don't use this field when auto-generating SQL queries in this case.

To solve the problem, you should manually generate an UPDATE SQL query for the TMSQuery.SQLUpdate.Text property. For example:

Code: Select all

  msQuery.SQLUpdate.Text :=
  ' UPDATE mytable1 ' +
  ' SET ' +
  '   MyField = :field ' +
  ' WHERE ' +
  '   id = :id ';

Re: Problem writing field using alias (MSQuery)

Posted: Tue 14 Oct 2014 13:30
by danilo.abranches
Thank you, i will do so.

Re: Problem writing field using alias (MSQuery)

Posted: Thu 16 Oct 2014 07:23
by azyk
Feel free to contact us if you have any further questions.