A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Access SQL Question



 
 
Thread Tools Display Modes
  #1  
Old July 10th, 2008, 04:11 PM posted to microsoft.public.access.queries
Kevin
external usenet poster
 
Posts: 910
Default Access SQL Question

I'm trying to UPDATE the value of a COUNT() operation into a field viz.
UPDATE table1 SET field = ( SELECT COUNT(*) FROM table2
WHERE table1.PrimaryKey = 1;

When I do this I always get the error message
"Operation must use an updateable query".

Anybody know how to do this correctly?

thanks,
  #2  
Old July 10th, 2008, 04:32 PM posted to microsoft.public.access.queries
Allen Browne
external usenet poster
 
Posts: 11,706
Default Access SQL Question

Perhaps a DCount() would work:

UPDATE table1 SET field1 = DCount("*", "table2")
WHERE table1.PK = 1;

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Kevin" wrote in message
...
I'm trying to UPDATE the value of a COUNT() operation into a field viz.
UPDATE table1 SET field = ( SELECT COUNT(*) FROM table2
WHERE table1.PrimaryKey = 1;

When I do this I always get the error message
"Operation must use an updateable query".

Anybody know how to do this correctly?

thanks,

  #3  
Old July 10th, 2008, 04:37 PM posted to microsoft.public.access.queries
bcap[_2_]
external usenet poster
 
Posts: 260
Default Access SQL Question

In general SQL terms you ARE doing it correctly. This insistence by Access
that you can't use non-updateable sub-queries in an UPDATE query is one of
it's most annoying "features".

You could probably get away with this (it doesn't smell so bad if you hold
your nose):

UPDATE table1 SET field = DCount("some_field", "table2") WHERE
table1.PrimaryKey = 1;

"Kevin" wrote in message
...
I'm trying to UPDATE the value of a COUNT() operation into a field viz.
UPDATE table1 SET field = ( SELECT COUNT(*) FROM table2
WHERE table1.PrimaryKey = 1;

When I do this I always get the error message
"Operation must use an updateable query".

Anybody know how to do this correctly?

thanks,



  #4  
Old July 10th, 2008, 04:43 PM posted to microsoft.public.access.queries
Kevin
external usenet poster
 
Posts: 910
Default Access SQL Question

Excellent suggestion. Works like a charm. Thanks much.

"Allen Browne" wrote:

Perhaps a DCount() would work:

UPDATE table1 SET field1 = DCount("*", "table2")
WHERE table1.PK = 1;

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Kevin" wrote in message
...
I'm trying to UPDATE the value of a COUNT() operation into a field viz.
UPDATE table1 SET field = ( SELECT COUNT(*) FROM table2
WHERE table1.PrimaryKey = 1;

When I do this I always get the error message
"Operation must use an updateable query".

Anybody know how to do this correctly?

thanks,


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:06 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.