D
david.barbetta
I would be happy to pay $50 via Paypal to the first person to
successfully answer my question.
I am using Access 2003 and Excel 2003 (I'm hoping to be able to pull
the output of the following query into Excel). I have two tables and
I'm trying to create a complex query. These table represent invoices
(Invoice) and delivery records (Ticket). Table structure:
Table 1: Invoice
inv_datebilled
inv_billno
inv_payor_type
inv_expected
inv_sitename
Table 2: Ticket
t_billno
td_therapy_type
td_drug_id
td_cost_ea
td_quantity
The tables are not linked via a relationship but the "inv_billno" &
"t_billno" items match up, and each invoice could have several tickets
(1 to many).
I'm trying to get the following info:
Select sum of (td_cost_ea * td_quantity)
from (union of the tables)
where inv_sitename = "Site 1"
and inv_payor_type = "Payor 1"
and td_therapy_type = "Therapy 1"
group rows by td_drug_id
group columns by quarters (Q1 2007 is 1/1/2007 to 3/31/2007, Q2 is
4/1/2007 to 6/30/2007, etc) based on inv_datebilled
So the output would be a table with a row for each drug_id and a
column for each calendar quarter. The data values would be a total
amount spent (td_cost_ea times td_quantity), which would sum all
entries where the conditions (e.g. inv_sitename = "Site 1") were
satisfied.
This could be done in one query or a query of a query. If you can't
do the entire thing or it can't be done, then if you could get me most
of the way along (e.g. columns are individual dates instead of
quarters) I would pay you something. Note that I'm hoping to send the
SQL programmatically from MS Excel so I think there's a limit on the
length of the SQL string.
Thanks!
successfully answer my question.
I am using Access 2003 and Excel 2003 (I'm hoping to be able to pull
the output of the following query into Excel). I have two tables and
I'm trying to create a complex query. These table represent invoices
(Invoice) and delivery records (Ticket). Table structure:
Table 1: Invoice
inv_datebilled
inv_billno
inv_payor_type
inv_expected
inv_sitename
Table 2: Ticket
t_billno
td_therapy_type
td_drug_id
td_cost_ea
td_quantity
The tables are not linked via a relationship but the "inv_billno" &
"t_billno" items match up, and each invoice could have several tickets
(1 to many).
I'm trying to get the following info:
Select sum of (td_cost_ea * td_quantity)
from (union of the tables)
where inv_sitename = "Site 1"
and inv_payor_type = "Payor 1"
and td_therapy_type = "Therapy 1"
group rows by td_drug_id
group columns by quarters (Q1 2007 is 1/1/2007 to 3/31/2007, Q2 is
4/1/2007 to 6/30/2007, etc) based on inv_datebilled
So the output would be a table with a row for each drug_id and a
column for each calendar quarter. The data values would be a total
amount spent (td_cost_ea times td_quantity), which would sum all
entries where the conditions (e.g. inv_sitename = "Site 1") were
satisfied.
This could be done in one query or a query of a query. If you can't
do the entire thing or it can't be done, then if you could get me most
of the way along (e.g. columns are individual dates instead of
quarters) I would pay you something. Note that I'm hoping to send the
SQL programmatically from MS Excel so I think there's a limit on the
length of the SQL string.
Thanks!