?
Solved

UPDATE statement with subquery

Posted on 2008-10-28
7
Medium Priority
?
391 Views
Last Modified: 2010-08-05
I have the following query and when I try to execute it I get a message of You have written a subquery that can return more than one field without using the EXISTS reserved work in the main querys from clause.   I'm using Microsoft Access and am not sure how to revise the query.  Any help would be greatly appreciated.  I'm using Microsoft Access 2003.


Thanks

update caserecords b
set unithours  = (select caseid, sum(casehours) as hours, int(sum(casehours)/60)&":"& (sum(casehours) mod 60)   as total_time from contactevents a
where b.id = a.caseid
group by caseid)

Open in new window

0
Comment
Question by:lfolku
[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
  • 4
  • 2
7 Comments
 
LVL 11

Expert Comment

by:miqrogroove
ID: 22825341
You have set unithours  = followed by several fields.  Access thinks you are trying to assign multiple values to the unnithours field.
0
 
LVL 11

Expert Comment

by:miqrogroove
ID: 22825390
I think you meant to do something like this:

UPDATE caserecords AS b LEFT JOIN contactevents AS a USING a.caseid=b.id
SET b.unithours = int(sum(a.casehours)/60)&":"& (sum(a.casehours) mod 60)
GROUP BY b.id

This is very complex though, you might want to try setting a simpler value to make sure the other syntax is correct first.
0
 
LVL 11

Accepted Solution

by:
miqrogroove earned 1000 total points
ID: 22825402
Oops the USING term is not correct..

UPDATE caserecords AS b LEFT JOIN contactevents AS a ON a.caseid=b.id
SET b.unithours = int(sum(a.casehours)/60)&":"& (sum(a.casehours) mod 60)
GROUP BY b.id
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:lfolku
ID: 22825480
miqrogroove,

I get a syntax error (missing operator) in query expression  'int(sum(a.casehours)/60)&":"& (sum(a.casehours) mod 60)
GROUP BY b.id'

Laurie
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 22825959
what about thius:
0
 
LVL 11

Expert Comment

by:miqrogroove
ID: 22826197
I can't get Jet to eat a multi-table update command.  Try angellll's idea, and if that doesn't work we can write a query loop.
0
 

Author Closing Comment

by:lfolku
ID: 31515918
Thanks for your help.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

765 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