Link to home
Start Free TrialLog in
Avatar of jmerulla
jmerullaFlag for United States of America

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!PreviousQuarter)
History.Category
is compared to
Temp.Ticker
Temp.Category
and values where the category is different will be returned.
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Try this:

SELECT * 
FROM History, Temp
WHERE History.Ticker = Temp.Ticker AND History.Quarter = Forms!Front!PreviousQuarter AND History.Category <> Temp.Category

Open in new window

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

Open in new window

Can you provide some sample data for the two tables and what you expect the result of the update to look like?
Avatar of jmerulla

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]![Previous Qtr]) AND (([Fund
History].[Full Name Category])<>[Temporary Add to History per Quarter2]![Full Name
Category]) AND (([Temporary Add to History per Quarter2].Ticker)=[Temporary 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.
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial