Advertisement

02.22.2008 at 01:12PM PST, ID: 23185896
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Access SQL Query - Combining 2 Queries Into 1 Set of Records

Asked by kabradley in Microsoft Access Database, SQL Query Syntax

Hello Experts!

This question loosely relates back to a question previously that GRayL was helping me with. After not finding a solution to that particular problem; I have decided to take a different approach and unfortunately as to be expected this has presented quite a few obstacles. Fortunately however, I have been able to leap over the first few and have come to somewhat of a road block that I can't seem to get around.

It comes in the form of querying data.

The tables I am dealing with are as follows:

tblFund
=====
fundID pk
FundName

tblInvestment
==========
InvestmentID - pk
RegID - fk to tblRegistration
FundName - fk to FundID in tblFund
Units - units of stock owned
Date -  if it was manually entered it'll have a date, if this record was a dividend it'll default to 12/30/1899
DivDate - if it is a dividend it will have a date, if not it'll default to the 12/30/1899 date

tblRegistration
===========
RegID - pk
RegName

tblStockDiv
========
StockDivID - pk
FundID - fk to FundID in tblFund
StockDate
StockAmount

Ok, so I've got a query that first compares the tblinvestment records with the tblStockDiv. If a dividend is in tblStockDiv it'll then select the associated tblInvestment records. After finding those records it compares the divdates to the stockDate in tblStockDiv. The query then actually displays the first (read: earliest) tblStockDiv that is available for each particular RegID and FundID.
The SQL is as follows:
SELECT Min(tblStockDiv.StockDate) AS FirstStockDate, tblFund.FundID, tblFund.FundName, tblRegistration.RegName, tblInvestment.RegID
FROM tblRegistration INNER JOIN ((tblFund INNER JOIN tblInvestment ON tblFund.FundID = tblInvestment.FundName) INNER JOIN tblStockDiv ON tblFund.FundID = tblStockDiv.FundID) ON tblRegistration.RegID = tblInvestment.RegID
WHERE (((tblStockDiv.StockDate) Not In (SELECT a.DivDate FROM tblInvestment As a WHERE tblInvestment.RegID = a.RegID AND tblInvestment.FundName = a.FundName)))
GROUP BY tblFund.FundID, tblFund.FundName, tblRegistration.RegName, tblInvestment.RegID, tblInvestment.FundName, tblInvestment.RegID;

Ok, so that is done and is displaying correctly. So now what I'm needing to do is:
Take that FirstStockDate and find the SUM of the units owned up until that FirstStockDate that are in tblInvestment for that RegID and FundID.
After finding the sum of the units, I need to multiply that by tblStockDiv.StockAmount that is equal to the FirstStockDate (i.e. the stock amount for the correct FundID on that FirstStockDate).

I can't seem to figure out how to do that though. I've tried using subqueries, etc. and just can't seem to get the results I'm needing.

Any help on the query would be greatly appreciate!

Start Free Trial
[+][-]02.22.2008 at 02:02PM PST, ID: 20961901

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.22.2008 at 02:08PM PST, ID: 20961953

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.22.2008 at 02:10PM PST, ID: 20961971

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.22.2008 at 02:20PM PST, ID: 20962051

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.22.2008 at 02:24PM PST, ID: 20962091

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.22.2008 at 02:47PM PST, ID: 20962351

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Access Database, SQL Query Syntax
Sign Up Now!
Solution Provided By: miqrogroove
Participating Experts: 2
Solution Grade: A
 
 
[+][-]02.22.2008 at 02:51PM PST, ID: 20962383

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.22.2008 at 03:01PM PST, ID: 20962462

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.22.2008 at 03:04PM PST, ID: 20962502

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.22.2008 at 03:15PM PST, ID: 20962615

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.05.2008 at 02:33PM PST, ID: 21055361

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628