Page 1 of 1

Retrieve correct table alias

Posted: Fri 08 Aug 2008 10:34
by tonisanta
Hi, is there a way to retrieve the correct alias of tables specified in the TMsQuery.SQL property? I tried with FieldDesc := TCRFieldDesc(msQuery1.GetFieldDesc(msQuery1.Fields));
but it doesn't seem to work since with a (stupid) sql like
select cust1.customerID, cust2.companyname
from customers cust1 inner join customers cust2 on cust1.customerid = cust2.customerid
it returns two times the same alias:
Origin: customers.customerID
Fieldname : customerID
TableAlias: cust2
Origin: customers.companyname
Fieldname : companyname
TableAlias: cust2
Obviously for customerID the tableAlias should be cust1. The problem appears having the same table two or more times with different aliases.
Is there another way to retrieve the alias or can you fix this issue?
Best regards
Toni Santa

Posted: Mon 18 Aug 2008 15:24
by Dimon
The enquiry is SQL server does not return aliases of tables, therefore we don't have an opportunity to determine correct alias, when query has the same table more than one times with different aliases.