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  

Update Query Problem



 
 
Thread Tools Display Modes
  #1  
Old November 21st, 2006, 08:37 AM posted to microsoft.public.access.queries
Nick Bradbury
external usenet poster
 
Posts: 28
Default Update Query Problem

Hi Everyone

I am having difficulty in creating a query that will update the status of
an order on completion of all the order details, I have pasted the SQL
below. What I am trying to achieve is that the status of the LabOrder is
changed from "Received" to "Testing Complete" once all the LabSamples in a
particular LabOrder are completed. I have made the query below to display
the LabOrders that have all the LabSamples completed but I am unable to use
this to perform an Update query, is there something else I should be doing.



SELECT tblLabSamples.LabNo, tblLabOrders.NoOfSamples, tblLabSamples.Status,
Count(tblLabSamples.Status) AS SumComp
FROM tblLabOrders INNER JOIN tblLabSamples ON tblLabOrders.LabNo =
tblLabSamples.LabNo
GROUP BY tblLabSamples.LabNo, tblLabOrders.NoOfSamples, tblLabSamples.Status
HAVING (((tblLabSamples.Status)="Completed"));


Many Thanks

Nick


  #2  
Old November 21st, 2006, 01:02 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Update Query Problem

You can do this all in one query or in three separate queries

One complex query using two subqueries
UPDATE tblLabOrders
SET tblLabOrders.Status = "Testing Complete"
WHERE tblLabOrders.LabNo IN
(SELECT X.LabNo
FROM tblLabSamples as X LEFT JOIN

(SELECT Tmp.LabNo
FROM TblLabSamples as Tmp
WHERE tmp.Status "Completed") as Y

ON X.LabNo = Y.LabNo
WHERE Y.LabNO is Null)

Three separate queries.
First query saved as qIncomplete. Get any labSample record that is NOT
complete
SELECT LabNo
FROM TblLabSamples
WHERE Status "Completed"

Second query saved as qAllComplete. Identify Laborders that are all
complete (no status other than completed)
SELECT tblLabOrders.LabNo
FROM tblLabOrders LEFT JOIN qIncomplete
ON tblLabOrders.LabNo = qIncomplete.LabNo
WHERE qIncomplete.LabNo is Null

Third query
UPDATE tblLabOrders
SET tblLabOrders.Status = "Testing Complete"
WHERE tblLabOrders.LabNo IN
(SELECT LabNo FROM qAllComplete)


"Nick Bradbury" wrote in message
...
Hi Everyone

I am having difficulty in creating a query that will update the status of
an order on completion of all the order details, I have pasted the SQL
below. What I am trying to achieve is that the status of the LabOrder is
changed from "Received" to "Testing Complete" once all the LabSamples in a
particular LabOrder are completed. I have made the query below to display
the LabOrders that have all the LabSamples completed but I am unable to
use this to perform an Update query, is there something else I should be
doing.



SELECT tblLabSamples.LabNo, tblLabOrders.NoOfSamples,
tblLabSamples.Status, Count(tblLabSamples.Status) AS SumComp
FROM tblLabOrders INNER JOIN tblLabSamples ON tblLabOrders.LabNo =
tblLabSamples.LabNo
GROUP BY tblLabSamples.LabNo, tblLabOrders.NoOfSamples,
tblLabSamples.Status
HAVING (((tblLabSamples.Status)="Completed"));


Many Thanks

Nick




  #3  
Old November 21st, 2006, 01:07 PM posted to microsoft.public.access.queries
Jeff Boyce
external usenet poster
 
Posts: 1,555
Default Update Query Problem

Nick

What happens if you start a new query, based on the query you use to find
"Completed"? I'm imagining a query that joins the underlying table to the
first query on the LabNo field, then updates the table's status...

--
Regards

Jeff Boyce
Microsoft Office/Access MVP
http://mvp.support.microsoft.com/

Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/

Microsoft Registered Partner
https://partner.microsoft.com/


"Nick Bradbury" wrote in message
...
Hi Everyone

I am having difficulty in creating a query that will update the status of
an order on completion of all the order details, I have pasted the SQL
below. What I am trying to achieve is that the status of the LabOrder is
changed from "Received" to "Testing Complete" once all the LabSamples in a
particular LabOrder are completed. I have made the query below to display
the LabOrders that have all the LabSamples completed but I am unable to

use
this to perform an Update query, is there something else I should be

doing.



SELECT tblLabSamples.LabNo, tblLabOrders.NoOfSamples,

tblLabSamples.Status,
Count(tblLabSamples.Status) AS SumComp
FROM tblLabOrders INNER JOIN tblLabSamples ON tblLabOrders.LabNo =
tblLabSamples.LabNo
GROUP BY tblLabSamples.LabNo, tblLabOrders.NoOfSamples,

tblLabSamples.Status
HAVING (((tblLabSamples.Status)="Completed"));


Many Thanks

Nick



  #4  
Old November 21st, 2006, 01:28 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Update Query Problem

Jeff,

Since the OP's original query was an aggregate query it can't be used in an
update query (except in a subquery in the where clause). If it is used
anywhere else the query becomes not updatable.


"Jeff Boyce" -DISCARD_HYPHEN_TO_END wrote in message
...
Nick

What happens if you start a new query, based on the query you use to find
"Completed"? I'm imagining a query that joins the underlying table to the
first query on the LabNo field, then updates the table's status...

--
Regards

Jeff Boyce
Microsoft Office/Access MVP
http://mvp.support.microsoft.com/

Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/

Microsoft Registered Partner
https://partner.microsoft.com/


"Nick Bradbury" wrote in message
...
Hi Everyone

I am having difficulty in creating a query that will update the status
of
an order on completion of all the order details, I have pasted the SQL
below. What I am trying to achieve is that the status of the LabOrder is
changed from "Received" to "Testing Complete" once all the LabSamples in
a
particular LabOrder are completed. I have made the query below to display
the LabOrders that have all the LabSamples completed but I am unable to

use
this to perform an Update query, is there something else I should be

doing.



SELECT tblLabSamples.LabNo, tblLabOrders.NoOfSamples,

tblLabSamples.Status,
Count(tblLabSamples.Status) AS SumComp
FROM tblLabOrders INNER JOIN tblLabSamples ON tblLabOrders.LabNo =
tblLabSamples.LabNo
GROUP BY tblLabSamples.LabNo, tblLabOrders.NoOfSamples,

tblLabSamples.Status
HAVING (((tblLabSamples.Status)="Completed"));


Many Thanks

Nick





  #5  
Old November 21st, 2006, 10:12 PM posted to microsoft.public.access.queries
Nick Bradbury
external usenet poster
 
Posts: 28
Default Update Query Problem

Hi John

Thanks for that it works fine.

Nick




"John Spencer" wrote in message
...
You can do this all in one query or in three separate queries

One complex query using two subqueries
UPDATE tblLabOrders
SET tblLabOrders.Status = "Testing Complete"
WHERE tblLabOrders.LabNo IN
(SELECT X.LabNo
FROM tblLabSamples as X LEFT JOIN

(SELECT Tmp.LabNo
FROM TblLabSamples as Tmp
WHERE tmp.Status "Completed") as Y

ON X.LabNo = Y.LabNo
WHERE Y.LabNO is Null)

Three separate queries.
First query saved as qIncomplete. Get any labSample record that is NOT
complete
SELECT LabNo
FROM TblLabSamples
WHERE Status "Completed"

Second query saved as qAllComplete. Identify Laborders that are all
complete (no status other than completed)
SELECT tblLabOrders.LabNo
FROM tblLabOrders LEFT JOIN qIncomplete
ON tblLabOrders.LabNo = qIncomplete.LabNo
WHERE qIncomplete.LabNo is Null

Third query
UPDATE tblLabOrders
SET tblLabOrders.Status = "Testing Complete"
WHERE tblLabOrders.LabNo IN
(SELECT LabNo FROM qAllComplete)


"Nick Bradbury" wrote in message
...
Hi Everyone

I am having difficulty in creating a query that will update the status
of an order on completion of all the order details, I have pasted the SQL
below. What I am trying to achieve is that the status of the LabOrder is
changed from "Received" to "Testing Complete" once all the LabSamples in
a particular LabOrder are completed. I have made the query below to
display the LabOrders that have all the LabSamples completed but I am
unable to use this to perform an Update query, is there something else I
should be doing.



SELECT tblLabSamples.LabNo, tblLabOrders.NoOfSamples,
tblLabSamples.Status, Count(tblLabSamples.Status) AS SumComp
FROM tblLabOrders INNER JOIN tblLabSamples ON tblLabOrders.LabNo =
tblLabSamples.LabNo
GROUP BY tblLabSamples.LabNo, tblLabOrders.NoOfSamples,
tblLabSamples.Status
HAVING (((tblLabSamples.Status)="Completed"));


Many Thanks

Nick






  #6  
Old November 22nd, 2006, 01:04 AM posted to microsoft.public.access.queries
Jeff Boyce
external usenet poster
 
Posts: 1,555
Default Update Query Problem

Oh! That explains why I've run into the non-updateable in that
circumstance! Thanks!

Jeff

"John Spencer" wrote in message
...
Jeff,

Since the OP's original query was an aggregate query it can't be used in

an
update query (except in a subquery in the where clause). If it is used
anywhere else the query becomes not updatable.


"Jeff Boyce" -DISCARD_HYPHEN_TO_END wrote in message
...
Nick

What happens if you start a new query, based on the query you use to

find
"Completed"? I'm imagining a query that joins the underlying table to

the
first query on the LabNo field, then updates the table's status...

--
Regards

Jeff Boyce
Microsoft Office/Access MVP
http://mvp.support.microsoft.com/

Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/

Microsoft Registered Partner
https://partner.microsoft.com/


"Nick Bradbury" wrote in message
...
Hi Everyone

I am having difficulty in creating a query that will update the status
of
an order on completion of all the order details, I have pasted the SQL
below. What I am trying to achieve is that the status of the LabOrder

is
changed from "Received" to "Testing Complete" once all the LabSamples

in
a
particular LabOrder are completed. I have made the query below to

display
the LabOrders that have all the LabSamples completed but I am unable to

use
this to perform an Update query, is there something else I should be

doing.



SELECT tblLabSamples.LabNo, tblLabOrders.NoOfSamples,

tblLabSamples.Status,
Count(tblLabSamples.Status) AS SumComp
FROM tblLabOrders INNER JOIN tblLabSamples ON tblLabOrders.LabNo =
tblLabSamples.LabNo
GROUP BY tblLabSamples.LabNo, tblLabOrders.NoOfSamples,

tblLabSamples.Status
HAVING (((tblLabSamples.Status)="Completed"));


Many Thanks

Nick






 




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 05:45 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.