Solved

UPDATE statement with subquery

Posted on 2008-10-28
7
383 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
  • 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 250 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now