Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Using Derived tables - Example 1
Wed, Jan 7 2009 5:16 PMPermanent Link

Richard Harding
Tim,

I am discovered Derived tables but I am have trouble making them work in a program.

The SQL is:

SELECT *
  FROM UserDefinedFields
     LEFT OUTER JOIN (SELECT * FROM JobFields WHERE JobID = 8004) T1
        ON T1.UserFieldID = UserDefinedFields.ID   
  WHERE UserDefinedFields.ClientType = 2
  ORDER BY Sequence

* drop a TEDBQuery component on a form
* set the SQL to the above
* define the persistent fields in the Field editor.

In the program:

 qyJobFields.SQL.Clear;
 qyJobFields.SQL.Add('SELECT * FROM UserDefinedFields AS UDF ');
 qyJobFields.SQL.Add('LEFT OUTER JOIN (SELECT * FROM JobFields WHERE JobID =  ');
 qyJobFields.SQL.Add(dmData.qyJobsForContact.FieldByName('ID').AsString);
 qyJobFields.SQL.Add(') T1 ON T1.UserFieldID = UserDefinedFields.ID ');
 qyJobFields.SQL.Add('WHERE UserDefinedFields.ClientType = 2 ');
 qyJobFields.SQL.Add('ORDER BY Sequence');
 qyJobFields.Open;

The open fails as the persistent fields are no longer available.  If the Derived table is
replaced by the real table (JobFields) then the persistent fields are available.

I can make it work by removing the persistent fields.

Richard Harding.
Thu, Jan 8 2009 7:50 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Richard,

<< The open fails as the persistent fields are no longer available.  If the
Derived table is replaced by the real table (JobFields) then the persistent
fields are available. >>

What is the error message that you're seeing ?

--
Tim Young
Elevate Software
www.elevatesoft.com

Thu, Jan 8 2009 2:44 PMPermanent Link

Richard Harding
>>What is the error message that you're seeing ?

EDatabaseError with message 'qyJobFields: Field 'X' not found'

I will send you a example project shortly.


Richard Harding
Image