Referencing other tables

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
kerino
Junior Boarder
Junior Boarder
Posts: 27
Joined: 26.06.2008, 10:04

Referencing other tables

Post by kerino »

Hi,
I have a table T1, which has a column 'dNum', and computed column.
I also have another table CT, which just contains a single field 'Conv' holding a conversion factor.
How can I define the computed column to hole (dNum * CT.Conv)?
If I use ...
'CREATE TABLE T1 (' ...etc.
'Comp1 COMPUTED BY (dNum * CT.Conv)'
I get an error saying CT.Conv does not belong to the referenced table.
How do I do this please?

Many thanks
btrewern
Expert Boarder
Expert Boarder
Posts: 193
Joined: 06.10.2005, 18:51

Post by btrewern »

Which DB are you using?

I don't expect you will be able to do this whatever database you are using. Try using a view instead.

In delphi you would do this using a calculated field and doing the calculation in the OnCalcFields event handler.

Regards,

Ben
kerino
Junior Boarder
Junior Boarder
Posts: 27
Joined: 26.06.2008, 10:04

Post by kerino »

Hi Ben,
I forgot to say I'm using Firebird, Zeos, Delphi5.
What the problem is, is that I have a column which holds a dimension in inches, but I need to display it in inches, cm, mm etc. (user selectable)
I thought a computed column would do the trick, but I'm open to suggestions.
I'll take a look at Views, as I haven't used them before.

Many thanks
Kerin
kerino
Junior Boarder
Junior Boarder
Posts: 27
Joined: 26.06.2008, 10:04

Post by kerino »

Hi,
I've had a look at creating a view, but still seem to have the same problem i.e. how do I reference a field from another table.
Is there another way to do this?
The actual conversion factor is a variable in the Delphi program, so is there any way I can reference this in the computed field?

Many thanks - Keirn
sandeep_c24
Expert Boarder
Expert Boarder
Posts: 158
Joined: 06.11.2005, 01:43

Post by sandeep_c24 »

He Keirn

If you want to use computed columns in database try this

CREATE TABLE T1 (' ...etc.
Comp1 COMPUTED BY (dNum * (select c.Conv from CT c where SOME_CONDITION))

As far as computed columns are concerned you can do what you want in the OnCalculate event.

Regards

Sandeep
kerino
Junior Boarder
Junior Boarder
Posts: 27
Joined: 26.06.2008, 10:04

Post by kerino »

Hi Sandeep,

Exactly what I wanted - it works great !!

Many thanks
Kerin
Post Reply