View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Laphan[_2_] Laphan[_2_] is offline
external usenet poster
 
Posts: 25
Default SQL Query Quandry

Hi All

I know I've got to post my schema, etc, but I think its more of a logic
thing than table-specific.

If you can imagine how an Excel pivot table would display it, I want all of
my sales people listed down the left hand side of my report, all my stock
categories listed along the top of my report and then for each value that
these 'axis's cover I want the sum of my qty sold field.

Getting this on an ASP page is my problem, but if I can get the desired
result in an Excel pivot table then I will be happy to continue the rest.

My basic 4 data fields are SALESPERSON, STOCKCAT, QTYSOLD and DATESOLD (the
last one being because I want to offer the user the ability to enter a date
range and this is what it will come from.

I have created a query that shows me the exact data that I want, but only
where there is a QTYSOLD for a SALESPERSON and STOCKCAT.

My actual problem is that I want to show all of the SALESPERSONs and
STOCKCATs available and if some don't have a value for the above then they
show a value of 0.00.

I've really been trying since you last helped me and I think the reason why
the above isn't working is because I need to perform a different kind of
JOIN so that I can get all of the SALESPERSONs and STOCKCATs from the
relevant tables.

The only problem with this is that my tables are as follows and when I do a
JOIN in MS Query it says it can't be done on more than 2 tables:


tbl_SALESPERSONS contains SALESPERSONID and SALESPERSONNAME (I need all of
the SALESPERSONNAME)

which is linked to the SALESPERSONID in

tbl_INVOICEHEADER contains SALESPERSONID, INVOICEID

which is linked to the INVOICEID in

tbl_INVOICELINES contains INVOICEID, STOCKID, QTYSOLD, DATESOLD (I need
QTYSOLD and DATESOLD)

which is linked to the STOCKID in

tbl_STOCK contains STOCKID, STOCKCATID

which is linked to the STOCKCATID in

tbl_STOCKCAT contains STOCKCATID, STOCKCATNAME (I need all of the
STOCKCATNAME)


How can I do this when I need the above to link of it all together??

Your help (as always) would be appreciated.

Rgds

Laphan