Retrieve correct table alias

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Posts: 55
Joined: Wed 04 Apr 2007 17:25

Retrieve correct table alias

Post by tonisanta » Fri 08 Aug 2008 10:34

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

Devart Team
Posts: 2885
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 18 Aug 2008 15:24

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.

Post Reply