|
|
#1 |
|
Fanatic Member
Join Date: Jan 00
Location: Outside your window
Posts: 548
![]() |
Ok here are the tables:
tblMainPurchase -Parent for tblPurchase. Holds information like total purchase, total tax charged, shipping, etc. tblPurchase -child of tblMainPurchase. Holds actuall items of the Purchase. ProductID, Price Charged for Each product, etc. tblProduct -Products to purchase tblPrice -Price categories for products. Example: tblProduct might have a TV item. tblPrice holds all the price items for that TV: Black 100$, Blue 200$, Green 300$. Now, all that works great... however, when I get to the reporting part it all breaks down. What I am trying to do is: Extract information for each product sold. Meaning, I want to make al ist like this: TV - Blue - Total Sold Units - 200 Black - Total Sold Units - 15 VCR Green - Total Units - 20 Green w\accessories - Total Units - 400 ...etc. Here is the query I am using for TSQL Code:
CREATE PROCEDURE sp_getSalesByDay @intDay varchar(2), @intMonth varchar(2), @intYear varchar(4) AS DECLARE @sql varchar(1000) SET @sql = "SELECT " + "tblMainPurchase.guidMainPurchaseID, tblMainPurchase.guidUserID, tblMainPurchase.dblTotalPurchase, tblMainPurchase.dblTaxPrice, tblMainPurchase.dblShipping, tblMainPurchase.dblCertificateValue, tblMainPurchase.datPurchased," + "tblPurchase.guidPurchaseID, tblPurchase.guidProductID, tblPurchase.guidPriceID, tblPurchase.intQuantity, tblPurchase.dblPrice, tblPurchase.datPurchased," + "tblProduct.charName," + "tblPrice.charPriceName " + " FROM tblMainPurchase " + "LEFT JOIN tblPurchase ON tblMainPurchase.guidMainPurchaseID = tblPurchase.guidMainPurchaseID LEFT JOIN tblProduct ON tblProduct.guidProductID = tblPurchase.guidProductID LEFT JOIN tblPrice ON tblProduct.guidProductID = tblPrice.guidProductID " + "WHERE DATEPART(YEAR, tblPurchase.datPurchased) ='" + @intYear + "' AND " + "DATEPART(MONTH, tblPurchase.datPurchased) ='" + @intMonth + "' AND " + "DATEPART(DAY, tblPurchase.datPurchased) ='" + @intDay + "' " + "ORDER BY tblProduct.charName, tblPurchase.guidPriceID" --Order by char name not ID, this way, they display alphabeticaly EXEC(@sql) GO I know I'm not joining them right... any ideas?
__________________
ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?
Last edited by invitro; Oct 31st, 2004 at 05:59 PM. |
|
|
|
|
|
#2 |
|
Fanatic Member
Join Date: Jan 00
Location: Outside your window
Posts: 548
![]() |
Ok so the problem lies with
tblPrice I took out that whole entire part and it works fine. For some reason it was joining EVERY price category with my tables... I still need to retrieve tblPrice items for correct price naming.. If we have a VCR, I want to report how many BLUE and ORANGE VCR's it sold.. not just the total. hmm... any ideas?
__________________
ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?
|
|
|
|
|
|
#3 |
|
Fanatic Member
Join Date: Jan 00
Location: Outside your window
Posts: 548
![]() |
ok i just fixed it...
tblPrice was comparing tblPrice.guidProductID not tblPrice.guidPriceID It works great now... arent you happy you didnt have to dig into that messy SQL string?
__________________
ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?
|
|
|
|
|
|
#4 | |
|
ASP.NET Moderator
Join Date: Feb 02
Location: Ulaan Baator GooGoo: Frog
Posts: 37,382
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Quote:
|
|
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|