Hello,
I am having a problem with a join. Either I am just not seeing the
obvious, it isn't possible, or I need to use a different approach. I
have an application with a vsflexgrid that needs to display the
following:
filenumber, BL, Container_BL, BL_HBL, HBL, Container_HBL
The tables look like:
CREATE TABLE tblFILE (
FileNumber int not null Primary Key,
status char(1) not null
)
CREATE table tblBL (
bl_Identity bigint not null primary key identity,
bl varchar(20) not null,
FileNumber BIGint not null,
CONSTRAINT FK_tblFILE_tblB L FOREIGN KEY (FileNumber) REFERENCES
tblFILE(FileNum ber)
)
CREATE TABLE tblCONTAINER (
ContainerID bigint not null primary key identity,
ContainerNumber varchar(20) not null
)
CREATE table tblCONTAINER_BL (
ContainerID bigint not null ,
BL_Identity bigint not null ,
CONSTRAINT FK_tblCONTAINER FOREIGN KEY (ContainerID) REFERENCES
tblCONTAINER(Co ntainerID),
CONSTRAINT FK_tblBL FOREIGN KEY (BL_Identity) REFERENCES
tblBL(BL_Identi ty),
constraint PK_tblBL_tblCON TAINER primary key (ContainerID,
BL_Identity)
)
CREATE TABLE tblHBL (
hbl_Identity bigint not null primary key identity,
hbl varchar(20) not null,
FileNumber BIGint not null,
bl_identity bigint,
CONSTRAINT FK_tblFILE_tblH BL FOREIGN KEY (FileNumber) REFERENCES
tblFILE(FileNum ber)
CONSTRAINT FK_tblBL FOREIGN KEY (bl_identity) REFERENCES
tblBL(bl_identi ty)
)
CREATE table tblCONTAINER_HB L (
ContainerID bigint not null ,
hbl_Identity bigint not null ,
CONSTRAINT FK_tblCONTAINER FOREIGN KEY (ContainerID) REFERENCES
tblCONTAINER(Co ntainerID),
CONSTRAINT FK_tblHBL FOREIGN KEY (hbl_Identity) REFERENCES
tblHBL(hbl_Iden tity),
constraint PK_tblHBL_tblCO NTAINER primary key (ContainerID,
hbl_Identity)
)
To explain this a little bit...a file has relations with zero to many
BLs, a BL has zero to many containers. A file also has zero to many
HBLs, an HBL has zero to many Containers. Also, a BL has zero to many
HBLs. An HBL will eventually always have a BL but because of the
business process, many months may go by without knowing what the BL is
so the stable relationship for the HBL is with the file. But when the
HBL has a relationship with a BL, it needs to be clear.
So my problem, I tried to make a view that shows each relationship but
I can't get it to show correctly.
CREATE VIEW fileselecthbl_b l_view as (
Select f1.FileNumber, f1.Status, f1.CustomerID, bl.BL_Identity, bl.BL,
hbl.HBL_Identit y, hbl.HBL,
chbl.ContainerI D, c1.ContainerNum ber from tblFile f1 left OUTER JOIN
tblHBL hbl
ON (f1.FileNumber = hbl.FileNumber) full OUTER JOIN tblBL bl ON
(bl.BL_Identity = hbl.BL_ID)
LEFT OUTER JOIN tblCONTAINER_HB L chbl ON (hbl.HBL_Identi ty =
chbl.HBL_ID) left outer join
tblCONTAINER c1 ON (chbl.Container ID = c1.ContainerIde ntity) )
But this doesn't give me what I need. This gives me 40 rows with a
filenumber and six with null in the filenumber. What I need is for the
hbl AND the bl to be joined to the initial tblFILE.
---This is vb code showing where it will be used.
With vsfgOpenedFiles
.TextMatrix(0, 0) = "File Number"
.TextMatrix(0, 1) = "File Status"
.TextMatrix(0, 2) = "BL"
.TextMatrix(0, 3) = "Container by BL"
.TextMatrix(0, 4) = "HBL"
.TextMatrix(0, 5) = "Container by HBL"
.AutoSize 0, 5
End With
----
I need to have rows that show FileNumber, Status, Bl, Container by BL,
HBL if it has a relationship with BL, Container by HBL.
If a BL does not have a relationship with an HBL then the row needs to
show FileNumber, Status, BL, Container by BL, Null, Null
If an HBL does not have a relationship with BL then it needs to be a
line with FileNumber, Status, Null, Null, HBL, Container by HBL.
Jeez, I am sorry this is so long. I don't know how else to explain my
problem. I am going to stop. I would appreciate anybody's ideas.
--rowan
I am having a problem with a join. Either I am just not seeing the
obvious, it isn't possible, or I need to use a different approach. I
have an application with a vsflexgrid that needs to display the
following:
filenumber, BL, Container_BL, BL_HBL, HBL, Container_HBL
The tables look like:
CREATE TABLE tblFILE (
FileNumber int not null Primary Key,
status char(1) not null
)
CREATE table tblBL (
bl_Identity bigint not null primary key identity,
bl varchar(20) not null,
FileNumber BIGint not null,
CONSTRAINT FK_tblFILE_tblB L FOREIGN KEY (FileNumber) REFERENCES
tblFILE(FileNum ber)
)
CREATE TABLE tblCONTAINER (
ContainerID bigint not null primary key identity,
ContainerNumber varchar(20) not null
)
CREATE table tblCONTAINER_BL (
ContainerID bigint not null ,
BL_Identity bigint not null ,
CONSTRAINT FK_tblCONTAINER FOREIGN KEY (ContainerID) REFERENCES
tblCONTAINER(Co ntainerID),
CONSTRAINT FK_tblBL FOREIGN KEY (BL_Identity) REFERENCES
tblBL(BL_Identi ty),
constraint PK_tblBL_tblCON TAINER primary key (ContainerID,
BL_Identity)
)
CREATE TABLE tblHBL (
hbl_Identity bigint not null primary key identity,
hbl varchar(20) not null,
FileNumber BIGint not null,
bl_identity bigint,
CONSTRAINT FK_tblFILE_tblH BL FOREIGN KEY (FileNumber) REFERENCES
tblFILE(FileNum ber)
CONSTRAINT FK_tblBL FOREIGN KEY (bl_identity) REFERENCES
tblBL(bl_identi ty)
)
CREATE table tblCONTAINER_HB L (
ContainerID bigint not null ,
hbl_Identity bigint not null ,
CONSTRAINT FK_tblCONTAINER FOREIGN KEY (ContainerID) REFERENCES
tblCONTAINER(Co ntainerID),
CONSTRAINT FK_tblHBL FOREIGN KEY (hbl_Identity) REFERENCES
tblHBL(hbl_Iden tity),
constraint PK_tblHBL_tblCO NTAINER primary key (ContainerID,
hbl_Identity)
)
To explain this a little bit...a file has relations with zero to many
BLs, a BL has zero to many containers. A file also has zero to many
HBLs, an HBL has zero to many Containers. Also, a BL has zero to many
HBLs. An HBL will eventually always have a BL but because of the
business process, many months may go by without knowing what the BL is
so the stable relationship for the HBL is with the file. But when the
HBL has a relationship with a BL, it needs to be clear.
So my problem, I tried to make a view that shows each relationship but
I can't get it to show correctly.
CREATE VIEW fileselecthbl_b l_view as (
Select f1.FileNumber, f1.Status, f1.CustomerID, bl.BL_Identity, bl.BL,
hbl.HBL_Identit y, hbl.HBL,
chbl.ContainerI D, c1.ContainerNum ber from tblFile f1 left OUTER JOIN
tblHBL hbl
ON (f1.FileNumber = hbl.FileNumber) full OUTER JOIN tblBL bl ON
(bl.BL_Identity = hbl.BL_ID)
LEFT OUTER JOIN tblCONTAINER_HB L chbl ON (hbl.HBL_Identi ty =
chbl.HBL_ID) left outer join
tblCONTAINER c1 ON (chbl.Container ID = c1.ContainerIde ntity) )
But this doesn't give me what I need. This gives me 40 rows with a
filenumber and six with null in the filenumber. What I need is for the
hbl AND the bl to be joined to the initial tblFILE.
---This is vb code showing where it will be used.
With vsfgOpenedFiles
.TextMatrix(0, 0) = "File Number"
.TextMatrix(0, 1) = "File Status"
.TextMatrix(0, 2) = "BL"
.TextMatrix(0, 3) = "Container by BL"
.TextMatrix(0, 4) = "HBL"
.TextMatrix(0, 5) = "Container by HBL"
.AutoSize 0, 5
End With
----
I need to have rows that show FileNumber, Status, Bl, Container by BL,
HBL if it has a relationship with BL, Container by HBL.
If a BL does not have a relationship with an HBL then the row needs to
show FileNumber, Status, BL, Container by BL, Null, Null
If an HBL does not have a relationship with BL then it needs to be a
line with FileNumber, Status, Null, Null, HBL, Container by HBL.
Jeez, I am sorry this is so long. I don't know how else to explain my
problem. I am going to stop. I would appreciate anybody's ideas.
--rowan
Comment