Ambiguous column name error

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
brace
Posts: 213
Joined: Wed 14 Feb 2007 08:26

Ambiguous column name error

Post by brace » Thu 24 Mar 2011 16:42

In a working application I tired to set a master detail relationship between 2 datasets (because I need to use this relationship in a report that I do with Report Builder), my application doesn't need this relaionship but it won't harm.

I have Master and Detail TMSQuery.

I set (at design time)

Code: Select all

Detail.MasterSource := Master
Detail.MasterField := Master_ID
Detail.DetailField := Master_ID
As I open the datasets I have AMBIGUOUS COLUMN NAME Master_ID. Please note that in the 2 queries Master_ID field appears only once. So why do I have this error?
There was an Order by Master_ID in the Detail query, but I remoevd it.

brace
Posts: 213
Joined: Wed 14 Feb 2007 08:26

Post by brace » Thu 24 Mar 2011 17:08

I forgot to tell I am using SDAC 5.0.0.3.

AndreyZ

Post by AndreyZ » Fri 25 Mar 2011 09:35

Hello,

To solve the problem, you should set the DetailField property in the following way:

Code: Select all

Detail.DetailField := DetailTableName.Master_ID
If it doesn't help, please specify the SQL code you are using in both queries.

brace
Posts: 213
Joined: Wed 14 Feb 2007 08:26

Post by brace » Fri 25 Mar 2011 10:25

I tried as you suggested but still nothing.

This is the sql of the Detail table. I create the master/Detail relationship on the ID_ATTIVITA field

Code: Select all

SELECT
  EDE.ID_EVENTO,
  EDE.ID_ATTIVITA,
  EA.NRO_RIGA AS TASK_NO
FROM
  EVA_DOMANDE_EVENTO EDE 

  LEFT OUTER JOIN EVA_ATTIVITA EA ON EDE.ID_ATTIVITA = EA.ID_ATTIVITA
WHERE
  EDE.ID_EVENTO = :ID_EVENTO
ORDER BY
  EDE.ID_ATTIVITA, EDE.NRO_RIGA
this is the query, the ambiguity is removed if I remove the JOIN.

I have the error on ID_ATTIVITA fileld, since that field is mentioned also in the join this causes a problem... How to solve?

AndreyZ

Post by AndreyZ » Fri 25 Mar 2011 14:14

I used your SQL code and changed the DetailFields property to EDE.ID_ATTIVITA. This solved the problem. If it doesn't help you, please try composing a small sample to demonstrate the problem and send it to andreyz*devart*com, including scripts to create the EVA_DOMANDE_EVENTO and EVA_ATTIVITA tables.

Post Reply