Corticus
Well-known Member
- Joined
- Apr 30, 2002
- Messages
- 1,579
Hi all,
I've got a nasty query to do.
In short, I need to make this:
become this:
Which I have sort of figured out how to do. I can make the query work as long as I know the max number of services, with SQL like:
SELECT QryRates.Name, QryRates.County, QryRates.ServiceName AS Serv1, QryRates.BillableRate AS Rate1, QryRates_1.ServiceName AS Serv2, QryRates_1.BillableRate AS Rate2, QryRates_2.ServiceName AS Serv3, QryRates_2.BillableRate AS Rate3
FROM (QryRates INNER JOIN QryRates AS QryRates_1 ON QryRates.Name = QryRates_1.Name) INNER JOIN QryRates AS QryRates_2 ON QryRates_1.Name = QryRates_2.Name
WHERE (((QryRates.ServiceID)=1) AND ((QryRates_1.ServiceID)=2) AND ((QryRates_2.ServiceID)=3));
But if there is no service 3, then the query return no records, since the "3" criteria for serv3 is not met,since there are no service 3.
Oh, what to do.
Thanks!
I apologize for the hideous SQL, but I wanted to show that I had done something to try to do this.
I've got a nasty query to do.
In short, I need to make this:
Book1 | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | Name | ServiceID | ServiceName | Rate | ||
2 | Alachua | 1 | HDM | 5.5 | ||
3 | Alachua | 2 | CM | 5.1 | ||
4 | Alachua | 3 | EAR | 4.8 | ||
5 | Citrus | 1 | HDM | 6.7 | ||
6 | Citrus | 2 | EAR | 3.9 | ||
7 | Columbia | 1 | HDM | 2.4 | ||
8 | Columbia | 2 | EAR | 7.6 | ||
9 | Columbia | 3 | CM | 3.4 | ||
10 | Columbia | 4 | PECA | 4.5 | ||
Sheet1 |
become this:
Book1 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
F | G | H | I | J | K | L | M | N | |||
1 | Name | Serv1 | Rate1 | Serv2 | Rate2 | Serv3 | Rate3 | Serv4 | Rate4 | ||
2 | Alachua | HDM | 5.5 | CM | 5.1 | EAR | 4.8 | ||||
3 | Citrus | HDM | 6.7 | EAR | 3.9 | ||||||
4 | Columbia | HDM | 2.4 | EAR | 7.6 | CM | 3.4 | PECA | 4.5 | ||
Sheet1 |
Which I have sort of figured out how to do. I can make the query work as long as I know the max number of services, with SQL like:
SELECT QryRates.Name, QryRates.County, QryRates.ServiceName AS Serv1, QryRates.BillableRate AS Rate1, QryRates_1.ServiceName AS Serv2, QryRates_1.BillableRate AS Rate2, QryRates_2.ServiceName AS Serv3, QryRates_2.BillableRate AS Rate3
FROM (QryRates INNER JOIN QryRates AS QryRates_1 ON QryRates.Name = QryRates_1.Name) INNER JOIN QryRates AS QryRates_2 ON QryRates_1.Name = QryRates_2.Name
WHERE (((QryRates.ServiceID)=1) AND ((QryRates_1.ServiceID)=2) AND ((QryRates_2.ServiceID)=3));
But if there is no service 3, then the query return no records, since the "3" criteria for serv3 is not met,since there are no service 3.
Oh, what to do.
Thanks!
I apologize for the hideous SQL, but I wanted to show that I had done something to try to do this.