我有TContractForm
带字段的表idcontract(primary key),idcntrtype(foreign key),date_begin,date_end,cost
。我还有 3 种类型的合同:
TRentWhouseContract
带字段idcontract,idclient,idpdtwhs
TRentShoppointContract
带字段idcontract,idclient,idshoppoint,idshoptype
TRentEquipContract
带字段idcontract,idclient,ideq,amount
idcntrtype
- 合同类型。TContractType
- idcntrtype(primary key),idcntrclass(foreign key),name
。TContractClass
- idcntrclass,name
。
我想用 columns 创建一个视图
idcontract,idclient,contract_type(name of type),contract_class(name of class),date_begin,date_end,cost
。
但是我的查询什么也没返回(我知道我在 TRentWhouseContract 表中有几个合同(其他表没有行)(它没有 idclient,因为如果某些表为空,我不知道如何从不同的表中获取相同的 idclient) .
select TCF.idcontract,
--idclient
TCF.date_begin,
TCF.date_end,
TCT.name as [type],
TCC.name as class,
TCF.cost
from TContractForm as TCF,
TRentEquipContract as TREC,
TRentShopPointContract as TRSPC,
TRentWhouseContract as TRWC,
TContractType as TCT,
TContractClass as TCC
where TCF.idcontract = TREC.idcontract or TCF.idcontract = TRSPC.idcontract
or TCF.idcontract = TRWC.idcontract and TCT.idcntrtype = TCF.idcntrtype
and TCT.idcntrclass = TCC.idcntrclass