![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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: |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
Sorry, I didn't include any sample data. I think this should do it. |
#5
| |||
| |||
|
#6
| |||
| |||
|
|
Oops I left something out. For the last two lines I need more than the filenumber. I also need the BL Container information. NULL NULL 200 bl1 NULL NULL NULL NULL NULL NULL 220 bl2 NULL NULL NULL NULL So, what I would need for this line is: 10222 O 200 bl1 NULL NULL 30 C10000000 10222 O 200 bl1 NULL NULL 31 C11111111 10111 O 220 bl3 NULL NULL 32 C12222222 Do I need to create two views? |
#7
| |||
| |||
|
|
Rowan (phantomtoe (AT) yahoo (DOT) com) writes: Oops I left something out. For the last two lines I need more than the filenumber. I also need the BL Container information. NULL NULL 200 bl1 NULL NULL NULL NULL NULL NULL 220 bl2 NULL NULL NULL NULL So, what I would need for this line is: 10222 O 200 bl1 NULL NULL 30 C10000000 10222 O 200 bl1 NULL NULL 31 C11111111 10111 O 220 bl3 NULL NULL 32 C12222222 Do I need to create two views? Thanks for the data! I believe I now get hinch about your data model. Here is a query that appears to correspond to your initial narrative, and indeed gives the above rows: SELECT FileNumber = coalesce(f1.FileNumber, f2.FileNumber), Status = coalesce(f1.status, f2.status), bl.bl_Identity, bl.bl, hbl.hbl_Identity, hbl.hbl, ContainerID = coalesce(cbl.ContainerID, chbl.ContainerID), coalesce(c1.ContainerNumber, c2.ContainerNumber) FROM tblFILE f1 LEFT JOIN (tblHBL hbl JOIN tblCONTAINER_HBL ch ON hbl.hbl_Identity = ch.hbl_Identity JOIN tblCONTAINER c1 ON ch.ContainerID = c1.ContainerID) ON f1.FileNumber = hbl.FileNumber FULL JOIN (tblBL bl JOIN tblCONTAINER_BL cbl ON bl.bl_Identity = cbl.BL_Identity JOIN tblCONTAINER c2 ON cbl.ContainerID = c2.ContainerID JOIN tblFILE f2 ON bl.FileNumber = f2.FileNumber) ON bl.bl_Identity = hbl.bl_identity The key here is that JOIN is an operator just like plus. The HBL should be inner joined to the container table, because once you have an HBL, you have the rest. So you join tblFILE with the tbale (HBL JOIN ch JOIN c1). Same applies for the FULL JOIN stuff. Not that the parantheses specifies *logical* evaluation order. The optmizer may apply all sorts of shortcuts, as long as the result is the the one specified by the expression. |
![]() |
| Thread Tools | |
| Display Modes | |
| |