Solved

Query with too many variables

Posted on 2013-01-03
5
453 Views
Last Modified: 2013-01-14
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.
0
Comment
Question by:jmerulla
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 38742033
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

0
 
LVL 30

Expert Comment

by:hnasr
ID: 38742322
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

0
 
LVL 32

Expert Comment

by:awking00
ID: 38744065
Can you provide some sample data for the two tables and what you expect the result of the update to look like?
0
 
LVL 2

Author Comment

by:jmerulla
ID: 38747570
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.
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 38747620
A couple of corrections and simplifying the syntax a bit:

SELECT temp.*, hist.*
FROM [Temporary Add to History per Quarter2] temp, [Fund History] hist
WHERE (hist.[Full Name Category] <> temp.[Full Name 
Category]) AND (temp.Ticker = hist.[Ticker]) AND (hist.Quarter = [Forms]![Front]![Previous Qtr]) 

Open in new window


If that still returns no records, then as requested above please provide some sample data meaning:

- Sample data representative of what you see in both tables
- Expected results based on the data given

(Mask any sensitive data as needed)

Or better yet, upload a sample database  (.mdb or accdb file) with the query, tables and data involved (again, masking any sensitive data).
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question