Accessing Join fields

Forum related to version 6.1.5 of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

yoda
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 07.07.2006, 17:21

Accessing Join fields

Postby yoda » 07.07.2006, 17:35

greetings,
I am running Delphi 6 with Zeoslib 6.1.5-stable and Mysql.

I have a TZQuery component on my form and have added SQL code
to the SQL property of the TZQuery component.

Normally I reference a field by using someting like:

MyQuery.fieldbyname('name').asstring

Well, I gone and used a join in my SQL code and don't know how to
reference a field ?

ie, select dealer.dnum, dealer.name,mixtemp.name from dealer left join
mixtemp on dealer.dnum = mixtemp.dnum

can't reference fields like
MyQuery.fieldbyname('dealer.dnum').asstring
as that gives a big error.

How do you do it ?

thanks,
D

User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Postby mdaems » 07.07.2006, 21:24

Use an alias for your field names like this:

Code: Select all

select dealer.dnum d_dnum, dealer.name d_name,mixtemp.name m_name from dealer left join mixtemp on dealer.dnum = mixtemp.dnum

Then you can do

Code: Select all

MyQuery.fieldbyname('d_dnum').asstring


Mark

zippo
Silver Boarder
Silver Boarder
Posts: 322
Joined: 12.10.2005, 18:01
Location: Slovenia

Postby zippo » 07.07.2006, 21:46

I use joined tables avery day and I always just state the name of the field after the word "Select". In your example:

Code: Select all

MyQuery.fieldbyname('dnum').asstring;


It has always worked OK for me. Post here if the tip os OK or not!

User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Postby mdaems » 08.07.2006, 11:04

That tip is OK as long as there are noduplicate field names, as is the case here.

zippo
Silver Boarder
Silver Boarder
Posts: 322
Joined: 12.10.2005, 18:01
Location: Slovenia

Postby zippo » 08.07.2006, 11:14

That's right. But I always use different field names... :)
And for the example it should work.


Return to “6.1.5”

Who is online

Users browsing this forum: No registered users and 1 guest