• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 535
  • Last Modified:

Syntax Error missing operator in query expression

My problem is that I need to sum a field (rate_commission.est_monthly_revenue) of a distantly related table.
products.plan_id = rate.plan_id    and rate.rate_id = rate_commission.rate_id

I have tried many variations on the form, here is the latest query:
Getting the following error while trying to update a table
Syntax Error missing operator in query expression 'abc.emr from ( select ...

update products
SET est_commission_fee =  abc.emr
from  ( select p.plan_id as plan_id, sum(rc.est_monthly_revenue) as emr
             from products p, rate r, rate_commission rc
          where  p.plan_id = r.plan_id
              and r.rate_id = rc.rate_id
          group by p.plan_id) abc
where plan_id = abc.plan_id

As I mentioned, I have tried a number of other variations to get this to work, but keep getting errors.
the select p.plan_id ... query works fine as it returns what I think is right, so I am dealing with the update portion of the statement.

Initial Attempt -- basic update statement:
UPDATE products
SET est_commission_fee = (sum(rc.est_monthly_revenue)
                          from products p, rate r, rate_commission rc
                          where  p.plan_id = r.plan_id
                          and r.rate_id = rc.rate_id
                          group by p.plan_id)

same error doesn't like the sum ...


Second Attempt -- create a view and then update state from view, but ...
CREATE VIEW viewProdEstMonthlyRev (
  plan_id number NOT NULL,
  est_monthly_revenue number NOT NULL
) AS
SELECT pr.plan_id, sum( rc.est_monthly_revenue ) as est_monthly_revenue
FROM rate r,  rate_commission rc, products pr
WHERE  pr.plan_id = r.plan_id
AND r.rate_id = rc.rate_id
GROUP BY pr.plan_id

getting a syntex error create table statement error

any assistance with the above would be appreciated.
0
JeffStone
Asked:
JeffStone
  • 6
  • 6
1 Solution
 
raopsnCommented:
Try this:

update products
INNER JOIN  ( select p.plan_id as plan_id, sum(rc.est_monthly_revenue) as emr
             from products p, rate r, rate_commission rc
          where  p.plan_id = r.plan_id
              and r.rate_id = rc.rate_id
          group by p.plan_id) as abc ON plan_id = abc.plan_id
SET est_commission_fee = abc.emr
0
 
JeffStoneAuthor Commented:
Getting Join Expression Not Supported error
0
 
JeffStoneAuthor Commented:
more specifically
Join expression not supported. (Error 3296)
Possible causes:

Your SQL statement contains multiple joins in which the results of the query can differ, depending on the order in which the joins are performed. You may want to create a separate query to perform the first join, and then include that query in your SQL statement.
The ON statement in your JOIN operation is incomplete or contains too many tables. You may want to put your ON expression in a WHERE clause.
0
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!

 
raopsnCommented:
Try this it is just an alias problem:

update products a
INNER JOIN  ( select p.plan_id as plan_id, sum(rc.est_monthly_revenue) as emr
             from products p, rate r, rate_commission rc
          where  p.plan_id = r.plan_id
              and r.rate_id = rc.rate_id
          group by p.plan_id) as abc ON a.plan_id = abc.plan_id
SET a.est_commission_fee = abc.emr
0
 
JeffStoneAuthor Commented:
a different error ...
Operation must use an updatable query. (Error 3073)
You tried to run, open, or modify a query that is not updatable.

Possible causes:

You attempted to run a query that tried to update a field that cannot be updated. For example, you may have created the query in such a way that you tried to update a field on the one side of a one-to-many relationship.
You tried to use the obsolete OpenQueryDef method on a query that is in a database opened for read-only access.
The database is read-only for one of the following reasons:

You used the OpenDatabase method or the Visual Basic Data control, and opened the database for read-only access.
The database file has been defined as read-only in your network operating system.
In a network environment, you do not have write privileges for the database file.
Close the database, resolve the read-only condition, and then reopen it for read/write access.

You do not have permission to make changes to the query. To change your permission assignments, see your system administrator or the query's creator.

0
 
raopsnCommented:
Let us try it in a different way ...

First create a separate query to calculate the SUM with the inner query, then use that in update query

Query1:
  SELECT p.plan_id as plan_id, sum(rc.est_monthly_revenue) as emr
  FROM products p
       INNER JOIN rate r ON  p.plan_id = r.plan_id
       INNER JOIN rate_commission rc ON  r.rate_id = rc.rate_id
  GROUP BY p.plan_id

Update Query:
UPDATE products SET est_commission_fee = DSUM("emr", "Query1", "plan_id = " & plan_id)
0
 
JeffStoneAuthor Commented:
I understand what you are trying to do, like a function in sql server ... the first query generates an error when you run it alone and / or try to save it.
SELECT p.plan_id as plan_id, sum(rc.est_monthly_revenue) as emr
  FROM products p
       INNER JOIN rate r ON  p.plan_id = r.plan_id
       INNER JOIN rate_commission rc ON  r.rate_id = rc.rate_id
  GROUP BY p.plan_id

generates -> Syntax error (missing operator) in query expression 'p.plan_id = r.plan_id inner join ...
0
 
JeffStoneAuthor Commented:
Not sure if this is a factor in what we have been discussing, but as an FYI ...
I am running Access 2003 hitting a 2000 file format ... I am assuming I would need to upgrade the db to 2003 for the dsum to work, is that right?
0
 
raopsnCommented:
No, it works with Access 2000
0
 
raopsnCommented:
Try this...

SELECT p.plan_id as plan_id, Count(rc.est_monthly_revenue) as emr
  FROM (products p
      INNER  JOIN rate r ON  p.plan_id = r.plan_id)
      INNER  JOIN rate_commission rc ON  r.rate_id = rc.rate_id
  GROUP BY p.plan_id
0
 
JeffStoneAuthor Commented:
ok, getting there that worked and I changed count to sum and we are good there.
now working on the 2nd part (update) ... got a dialog about updating xx rows clicked ok
and then got an error dialog
Microsoft Office Access can't update all the records in the update query
due to type conversion failure, 716 records dur to key violations, 0 records due to lock violations and 0 records due to validation violations.
So you want to continue running this type of action query anyway?

which is ok, because the plan_id field is null in some records ....
so thanks, I very much appreciate you help.
0
 
raopsnCommented:
Glad to help you
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now