To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > ASP, VB Script

Reply Post New Thread
 
Thread Tools Display Modes
Old Oct 31st, 2004, 04:38 PM   #1
invitro
Fanatic Member
 
invitro's Avatar
 
Join Date: Jan 00
Location: Outside your window
Posts: 547
invitro is an unknown quantity at this point (<10)
Resolved messy TSQL v ASP [RSLVD]

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
What I get.. are some wierd results. I get the resuls, but more then I hoped for... I get like 15 results where my test enivornment has only a couple of values in tblMainPurchase and tblPurchase.

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 04:59 PM.
invitro is offline   Reply With Quote
Old Oct 31st, 2004, 04:51 PM   #2
invitro
Fanatic Member
 
invitro's Avatar
 
Join Date: Jan 00
Location: Outside your window
Posts: 547
invitro is an unknown quantity at this point (<10)
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?
invitro is offline   Reply With Quote
Old Oct 31st, 2004, 04:59 PM   #3
invitro
Fanatic Member
 
invitro's Avatar
 
Join Date: Jan 00
Location: Outside your window
Posts: 547
invitro is an unknown quantity at this point (<10)
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?
invitro is offline   Reply With Quote
Old Oct 31st, 2004, 10:45 PM   #4
mendhak
ASP.NET Moderator
 
mendhak's Avatar
 
Join Date: Feb 02
Location: Ulaan Baator GooGoo: Frog
Posts: 38,161
mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)mendhak has a brilliant future (2000+)
Quote:
Originally posted by invitro

arent you happy you didnt have to dig into that messy SQL string?
You bet. I was actually going to turn my monitor on for a change.
mendhak is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > ASP, VB Script


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:26 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.