Reeco
Muse
- Joined
- Aug 11, 2005
- Messages
- 551
Hi, hope someone can help.
I have a Crystal report that is basically a list of route cards (sometimes known as works orders or job cards). I need to do some analysis on which customers these route cards were for. Usually, these route cards are linked to a contract which makes it easy to return the customer code, however where they are not linked I would like to use an SQL expression to dig into the database and return the customer code from the first contract associated with the part number/issue combination on the route card.
This involves three tables. I need to link the route_cards table to the contract_parts table and return records where the part number and issue matches. I then need to link to the contracts table, return the cust_code field and select the first of these. Here's what I have so far:
(
Select FIRST ("cust_code")
From
"radandba"."contracts" "contracts"
INNER JOIN "radandba"."contract_parts" "contract_parts" ON ("contract_parts"."contract_no" = "contracts"."contract_no")
INNER JOIN "radandba"."route_cards" "route_cards" On ("contract_parts"."part_num" = "route_cards"."part_num" AND "contract_parts"."issue" = "route_cards"."issue")
Where ("contract_parts"."contract_no" = "contracts"."contract_no" AND
"contract_parts"."part_num" = "route_cards"."part_num" AND
"contract_parts"."issue" = "route_cards"."issue")
)
The above is returning the first cust_code from the entire contracts table, not the subset that I need.
Any help would be appreciated.
I have a Crystal report that is basically a list of route cards (sometimes known as works orders or job cards). I need to do some analysis on which customers these route cards were for. Usually, these route cards are linked to a contract which makes it easy to return the customer code, however where they are not linked I would like to use an SQL expression to dig into the database and return the customer code from the first contract associated with the part number/issue combination on the route card.
This involves three tables. I need to link the route_cards table to the contract_parts table and return records where the part number and issue matches. I then need to link to the contracts table, return the cust_code field and select the first of these. Here's what I have so far:
(
Select FIRST ("cust_code")
From
"radandba"."contracts" "contracts"
INNER JOIN "radandba"."contract_parts" "contract_parts" ON ("contract_parts"."contract_no" = "contracts"."contract_no")
INNER JOIN "radandba"."route_cards" "route_cards" On ("contract_parts"."part_num" = "route_cards"."part_num" AND "contract_parts"."issue" = "route_cards"."issue")
Where ("contract_parts"."contract_no" = "contracts"."contract_no" AND
"contract_parts"."part_num" = "route_cards"."part_num" AND
"contract_parts"."issue" = "route_cards"."issue")
)
The above is returning the first cust_code from the entire contracts table, not the subset that I need.
Any help would be appreciated.
