Get the Fields Table (fields corresponding table)
Get the Fields Table (fields corresponding table)
Hy I have a SELECT like this:
SELECT
f_a, --t_a
f_b --t_b -> alias C
FROM
t_a JOIN t_b AS c ON .....
is there is a was to get the information that field f_b is from the table with alias C ?
In the components you know (zeos ^^ ) i could do a
S:=Q.SqlParser.SqlFields.FindByName('',Q.Fields.FieldName).Table;
S:=Q.SqlParser.Aliases[Q.SqlParser.Tables.IndexOf(S)];
SELECT
f_a, --t_a
f_b --t_b -> alias C
FROM
t_a JOIN t_b AS c ON .....
is there is a was to get the information that field f_b is from the table with alias C ?
In the components you know (zeos ^^ ) i could do a
S:=Q.SqlParser.SqlFields.FindByName('',Q.Fields.FieldName).Table;
S:=Q.SqlParser.Aliases[Q.SqlParser.Tables.IndexOf(S)];
You can use the following code (add CRAccess unit to USES):
Code: Select all
var
TableInfo: TCRTableInfo;
Name, Alias: string;
begin
TableInfo := TCRFieldDesc(PgQuery1.GetFieldDesc('f_b')).TableInfo;
if TableInfo nil then begin
Name := TableInfo.TableName;
Alias := TableInfo.TableAlias;
end;
end;
thnx a lot for your awnser but this doesnt work. i tried different ways the last houres but the problem seems always the same:
TCRTablesInfo.FTableNameList
as well as
TCRTablesInfo.FTableAliasList
always contains only one line with the first table of my select script (auftg).
your code is returning auftg always, too.
the script is looking like this:
perhaps you see the problem on your first look, if not, i have to try to break down my script to a smaller example.
TCRTablesInfo.FTableNameList
as well as
TCRTablesInfo.FTableAliasList
always contains only one line with the first table of my select script (auftg).
your code is returning auftg always, too.
the script is looking like this:
perhaps you see the problem on your first look, if not, i have to try to break down my script to a smaller example.
Code: Select all
SELECT
COALESCE(ag_akbz, lang_artbez(ag_aknr, prodat_languages.customerlang(ag_lkn))) AS art_ak_bez1,
ak_znr,
ak_rust,
ak_mat,
ak_fertk,
ak_matk,
ak_awkost,
adkl.ad_fa1 AS ADKL_AD_FA1,
adkl.ad_fa2 AS ADKL_AD_FA2,
adkl.ad_str AS ADKL_AD_STR,
adkl.ad_plz AS ADKL_AD_PLZ,
adkl.ad_ort AS ADKL_AD_ORT,
a1_vers AS ADK1_A1_VERSART,
ak_zolp1b AS art_ak_zolp1b1,
lang_artmgc_id (ag_mcv, prodat_languages.customerlang(ag_lkn)) AS MGCODE_ME_BEZ1,
ag_dokunr AS AUFTG_AG_N,
atd_txt_rtf,
atd_txt1_rtf,
atd_txt AS AUFZUTXT_AZ_ZUS,
atd_txt1 AS AUFZUTXT_AZ_ZUS1,
atd_ap,
ag_txt_rtf AS auftg_ag_azutx,
(SELECT SUM(az_anz*az_abzubetrag) FROM auftgabzu WHERE az_ag_id=ag_id) AS abzusum,
lang_abzu(ag_zunr1, :LANG) AS AUFTG_AG_TXAZ1,
lang_abzu(ag_zunr2, :LANG) AS AUFTG_AG_TXAZ2,
lang_abzu(ag_zunr3, :LANG) AS AUFTG_AG_TXAZ3,
lang_abzu(ag_zunr4, :LANG) AS AUFTG_AG_TXAZ4,
lang_abzu(ag_zunr5, :LANG) AS AUFTG_AG_TXAZ5,
lang_abzu(ag_zunr6, :LANG) AS AUFTG_AG_TXAZ6,
auftg.*,
adk.*,
adk_.*,
bewa.*
FROM
auftg AS auftg JOIN art ON ak_nr=ag_aknr
JOIN adk ON ad_krz=ag_lkn
JOIN adk AS adkl ON adkl.ad_krz=ag_krzl
LEFT OUTER JOIN auftgdokutxt ON atd_dokunr=ag_dokunr
LEFT OUTER JOIN adk1 AS adk_ ON a1_krz=adk.ad_krz
LEFT OUTER JOIN bewa ON wa_einh=a1_waco
WHERE
ag_dokunr=:ag_dokunr
ORDER BY
ag_astat, ag_nr, ag_pos