R
ryguy7272
I am working with this SQL:
SELECT SharePrices.StockSymbol, SharePrices.StockPrice AS StartPrice,
SharePrices_2.StockPrice AS EndPrice,
DateAdd("d",-21*(365/250),[Forms]![frmMstr]![cboEnd]) AS Date30Start,
DateAdd("d",0,[Forms]![frmMstr]![cboEnd]) AS Date30End,
(SharePrices_2.StockPrice-SharePrices.StockPrice)/SharePrices.StockPrice AS
Pct_Return
FROM (tblStocksGroup INNER JOIN SharePrices ON
tblStocksGroup.Ticker=SharePrices.StockSymbol) INNER JOIN SharePrices AS
SharePrices_2 ON tblStocksGroup.Ticker=SharePrices_2.StockSymbol
GROUP BY SharePrices.StockSymbol, SharePrices.StockPrice,
SharePrices_2.StockPrice;
Darly S helped me out this, big time. It’s pretty close to what I was
looking for, but it definitely needs a tweak or two. Let me describe what
I’m trying to do. I have a table of stock symbols, historical stock prices,
and date. I have another table with stock symbols and all sorts of other
criteria. There is a join line connecting the stock symbols field in each
table. Daryl gave me the idea of using a table for SharePrices and another
table for SharePrices2. When the query runs, I see the following:
Stock Symbol, StartPrice, EndPrice, StartDate, EndDate, and PercentReturn
This is what I want, except the query is creating a Cartesian Product. I
think I need a GroupBy clause to prevent the Cartesian Product from
occurring. Then, when it runs, I think Access will return the correct
StartDate and the correct EndDate; right now it disaplay ALL DATES.
Furthermore, it displays every possible combination of StartPrice and
EndPrice, thus the Cartesian Product.
Just to give a little more information, I have a form, named frmMstr. The
form has 20 checkboxes and one combobox, from where I choose a date. I have
a summary query that uses these 20 checkboxes; that works fine. I’m trying
to feed the results of this query, as well as three others (the three others
will work fine once I figure out this one). I’m trying to set this up so a
user can pick a date from the combobox and the query will automatically take
that date (the EndDate) and subtract 30 days from it (the StartDate). Then,
the query will calculate the PercentReturn as
((EndDate-StartDate)/StartDate). How can I modify my SQL (above) to do that?
Thanks so much!
Ryan---
SELECT SharePrices.StockSymbol, SharePrices.StockPrice AS StartPrice,
SharePrices_2.StockPrice AS EndPrice,
DateAdd("d",-21*(365/250),[Forms]![frmMstr]![cboEnd]) AS Date30Start,
DateAdd("d",0,[Forms]![frmMstr]![cboEnd]) AS Date30End,
(SharePrices_2.StockPrice-SharePrices.StockPrice)/SharePrices.StockPrice AS
Pct_Return
FROM (tblStocksGroup INNER JOIN SharePrices ON
tblStocksGroup.Ticker=SharePrices.StockSymbol) INNER JOIN SharePrices AS
SharePrices_2 ON tblStocksGroup.Ticker=SharePrices_2.StockSymbol
GROUP BY SharePrices.StockSymbol, SharePrices.StockPrice,
SharePrices_2.StockPrice;
Darly S helped me out this, big time. It’s pretty close to what I was
looking for, but it definitely needs a tweak or two. Let me describe what
I’m trying to do. I have a table of stock symbols, historical stock prices,
and date. I have another table with stock symbols and all sorts of other
criteria. There is a join line connecting the stock symbols field in each
table. Daryl gave me the idea of using a table for SharePrices and another
table for SharePrices2. When the query runs, I see the following:
Stock Symbol, StartPrice, EndPrice, StartDate, EndDate, and PercentReturn
This is what I want, except the query is creating a Cartesian Product. I
think I need a GroupBy clause to prevent the Cartesian Product from
occurring. Then, when it runs, I think Access will return the correct
StartDate and the correct EndDate; right now it disaplay ALL DATES.
Furthermore, it displays every possible combination of StartPrice and
EndPrice, thus the Cartesian Product.
Just to give a little more information, I have a form, named frmMstr. The
form has 20 checkboxes and one combobox, from where I choose a date. I have
a summary query that uses these 20 checkboxes; that works fine. I’m trying
to feed the results of this query, as well as three others (the three others
will work fine once I figure out this one). I’m trying to set this up so a
user can pick a date from the combobox and the query will automatically take
that date (the EndDate) and subtract 30 days from it (the StartDate). Then,
the query will calculate the PercentReturn as
((EndDate-StartDate)/StartDate). How can I modify my SQL (above) to do that?
Thanks so much!
Ryan---