Page 1 of 1

Is is possible to get the field expression from TMyQuery?

Posted: Wed 10 Aug 2011 16:01
by Justmade
SQL :
SELECT Table1.FieldA, CONCAT(Table1.FieldB,TABLE2.FieldC) AS FieldD
FROM Table1 LEFT JOIN Table2.....

Is it possible to get back CONCAT(Table1.FieldB,TABLE2.FieldC) from TMyQuery or TField of FieldD?

In TField, FieldD FieldName is of cause FieldD but the origin is also FieldD.

I would like the original expression (base on user choice of filters etc) to create another SQL with Where or so.

Thanks you!

Posted: Thu 11 Aug 2011 10:12
by AndreyZ
Hello,

The point is that when you use alias, MySQL returns alias for both field name and field original name. You can change your SQL code basing on your users' choice. Here is an example:

Code: Select all

SELECT Table1.FieldA, CONCAT(Table1.FieldB,TABLE2.FieldC) AS FieldD 
FROM Table1 LEFT JOIN Table2.....

SELECT Table1.FieldA, CONCAT(Table1.FieldB,TABLE2.FieldC)
FROM Table1 LEFT JOIN Table2.....
or
SELECT Table1.FieldA, CONCAT(Table1.FieldB,TABLE2.FieldC) AS 'CONCAT(Table1.FieldB,TABLE2.FieldC)'
FROM Table1 LEFT JOIN Table2.....