如何使用MSSQL从联接查询的字段中获取表名? (相当于mysql_field_table) [英] How to get the table name from a field in a join query with MSSQL? (mysql_field_table equivalent)

查看:104
本文介绍了如何使用MSSQL从联接查询的字段中获取表名? (相当于mysql_field_table)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ADO 在Delphi中做一个查询管理器,我需要知道一个查询将返回的所有字段,无论它有多复杂和有多少他们将拥有。我想调用一个函数,该函数返回给我,将在特定查询中返回的所有字段,以及字段信息,例如表格,此字段的来源。

I'm doing a query manager in Delphi using ADO, I need to know all fields that will be returned by a query, does no matter how complex and how much joins they will have. I want to call a function, that return to me, all fields that will be returned in a specific query, and fields information, like table what is this field from.

在带有php的mysql中,我有命令 mysql_field_table ,在此命令中,我传递结果对象和字段索引,此命令为我返回表名。

In mysql with php, I have the command mysql_field_table, in this command I pass the result object and the field index and this command return the table name for me.

好吧,这是我的梦想,从查询的字段索引中获取表名:

Well, that is my dream, get the table name from a field index in a query like:

SELECT * FROM TableOne Left Join Table2 ON Table2.MasterField = Table1.KeyField


推荐答案

您可以使用 TADODataSet 来获取 Recordset ,对 Fields 集合,并获得像这样的表/字段名称:

You could use a TADODataSet to fetch the Recordset, iterate the Fields collection, and get the tables/fields names like this:

for I := 0 to ADODataSet1.Recordset.Fields.Count - 1 do
begin
  TableName := ADODataSet1.Recordset.Fields[i].Properties['BASETABLENAME'].Value;
  FieldName := ADODataSet1.Recordset.Fields[i].Properties['BASECOLUMNNAME'].Value;
end;

这篇关于如何使用MSSQL从联接查询的字段中获取表名? (相当于mysql_field_table)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆