Go Back   CodingForums.com > :: Server side development > ASP.NET

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-14-2005, 07:15 PM   PM User | #1
reverendleo
New Coder

 
Join Date: May 2005
Location: The Lone Star State
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
reverendleo is an unknown quantity at this point
Query based on a query

Hello!

I'm currently developing a web app. that will pull data from an MS Access database. The original queries were developed in Access, and one query is based on another. I'm trying to replicate this with VB.net. Here are the SQL statements:

qryMonthbyLoad = SELECT tblMain.Date, tblSub.LoadCount, tblSub.AvgCYLoad, [LoadCount]*[AvgCYLoad] AS Total
FROM tblMain INNER JOIN tblSub ON tblMain.ID = tblSub.ID
WHERE (((tblMain.Date) Between [1st Day] And [2nd Day]) AND ((tblSub.LoadCount)>0));

query2 = SELECT Sum(qryMonthByLoad.Total) AS SumOfTotal
FROM qryMonthByLoad;

I'm not quite sure the best way to approach this with VB.net, as it doesn't seem to like selecting from a query.

Any advice would be great!

Thanks!
reverendleo is offline   Reply With Quote
Old 09-14-2005, 09:38 PM   PM User | #2
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
You could probably combine the two queries into one, and add another column for the sum, but right now I don't have time to look at it in dept, nor do I have access installed. But you could try just runing the same query but with the sum function.
Code:
query2 = SELECT Sum([LoadCount]*[AvgCYLoad]) AS SumOfTotal FROM tblMain INNER JOIN tblSub ON tblMain.ID = tblSub.ID
WHERE (((tblMain.Date) Between [1st Day] And [2nd Day]) AND ((tblSub.LoadCount)>0));
Good luck
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 09-19-2005, 09:21 PM   PM User | #3
reverendleo
New Coder

 
Join Date: May 2005
Location: The Lone Star State
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
reverendleo is an unknown quantity at this point
Thanks Brandoe!

That works! I needed to modify the SQL to recognize the dates (good 'ole #)

Here's what it ended up being:

Code:
Dim strSQL2 as String = "SELECT Sum([LoadCount]*[AvgCYLoad]) AS SumOfTotal " & _
							"FROM tblMain INNER JOIN tblSub ON tblMain.ID = tblSub.ID " & _
							"WHERE (((tblMain.Date)>=#" & TextDay1.Text & "# And (tblMain.Date)<=#" & TextDay2.Text & "#) AND ((tblSub.LoadCount)>0));"
You guys are great, always a big help!
reverendleo is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 +1. The time now is 12:29 PM.


Advertisement
Log in to turn off these ads.