简体   繁体   中英

How to get the table name from a column in a join query with SQL Server and FIREDAC?

I looking for get metadata on a TFDQuery (FireDAC).

I have this query:

SELECT * 
FROM Table1 t1 
INNER JOIN Table2 t2 ON t1.Code = t2.code

I would like to know the column information (table name, the real column name in the table, ....)

I find this post : How to get the table name from a field in a join query with MSSQL? (mysql_field_table equivalent) but I have not the same structure on FireDac.

As RBA already mentioned you have to enable ExtendedMetaData in the connection first. When done you can get the field column description via query.GetFieldColumn(field) and access the table and column name with its ActualOriginTabName and ActualOriginColName properties.

column := query.GetFieldColumn(field);
orgTableName := column.ActualOriginTabName;
orgColumnName := column.ActualOriginColName;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM