jmerulla
asked on
Query with too many variables
I am trying to write an update query but I can't get the initial select query right. I am hoping I am making this more difficult than it needs to be but I am stuck.
I have two tables - Temp (shortened for here) and History. They have all the same fields (I perform calculations in temp before appending it to history) and the link is ticker. I need to write a query to return values where ticker in the two tables is equal, quarter from history references the field on a form, and category from one table does not equal category from the other.
In other words, I want the values where
History.Ticker
History.Quarter (Form!Front!PreviousQuarte r)
History.Category
is compared to
Temp.Ticker
Temp.Category
and values where the category is different will be returned.
I have two tables - Temp (shortened for here) and History. They have all the same fields (I perform calculations in temp before appending it to history) and the link is ticker. I need to write a query to return values where ticker in the two tables is equal, quarter from history references the field on a form, and category from one table does not equal category from the other.
In other words, I want the values where
History.Ticker
History.Quarter (Form!Front!PreviousQuarte
History.Category
is compared to
Temp.Ticker
Temp.Category
and values where the category is different will be returned.
One way is to select records using INNER JOIN, then apply the where clause.
UPDATE HISTORY INNER JOIN Temp ON History.Ticker = Temp.Ticker
SET HISTORY.fld1 = Temp.fld1, HISTORY.fld2 = Temp.fld2
WHERE History.Quarter = Form!Front!PreviousQuarter AND History.Category <> Temp.Category
Can you provide some sample data for the two tables and what you expect the result of the update to look like?
ASKER
Here is what I have and the query doesn't return anything -
SELECT [Temporary Add to History per Quarter2].*, *
FROM [Temporary Add to History per Quarter2], [Fund History]
WHERE ((([Fund History].Quarter)=[Forms]! [Front]![P revious Qtr]) AND (([Fund
History].[Full Name Category])<>[Temporary Add to History per Quarter2]![Full Name
Category]) AND (([Temporary Add to History per Quarter2].Ticker)=[Tempora ry Add to
History per Quarter2]![Ticker]));
The temp file is there and the field on the form is correct.
In the end, I want it to return a table like this -
Ticker Quarter Recommendation Full Name Category
AOGIX 2012-9-30 1 Aggressive Allocation
So I can make an update query to change recommendation from 1 to 2.
SELECT [Temporary Add to History per Quarter2].*, *
FROM [Temporary Add to History per Quarter2], [Fund History]
WHERE ((([Fund History].Quarter)=[Forms]!
History].[Full Name Category])<>[Temporary Add to History per Quarter2]![Full Name
Category]) AND (([Temporary Add to History per Quarter2].Ticker)=[Tempora
History per Quarter2]![Ticker]));
The temp file is there and the field on the form is correct.
In the end, I want it to return a table like this -
Ticker Quarter Recommendation Full Name Category
AOGIX 2012-9-30 1 Aggressive Allocation
So I can make an update query to change recommendation from 1 to 2.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window