0

I need to update a column called PrebookCB in a table called Workorders and set it to 1 if the CustomerStatus column in Table Customers equals the string 'Good - Prebook'. I have tried various joins ect and cant seem to get it to work. This seems to be the closest. there would be multiple Workorders for each customer. Workorders have a column called CustomerID that matches the Customers primary index column called CustomerID

UPDATE Workorders
       JOIN Customers
       ON Workorders.CustomerID = Customers.CustomerID
SET    Workorders.PrebookCB = 1
WHERE  Customers.CustomerStatus = 'Good - Prebook'
0

2 Answers 2

2

Did you try this

UPDATE Workorders SET PrebookCB = 1 
WHERE CustomerID IN 
    (SELECT CustomerID FROM Customers 
    WHERE CustomerStatus = 'Good - Prebook')
Sign up to request clarification or add additional context in comments.

2 Comments

For some reason 0 rows are affected but I know that 290 customers have the CustomerStatus of 'Good - Prebook'. What else could be affecting it?
Can you just run "SELECT CustomerID FROM Customers WHERE CustomerStatus = 'Good - Prebook'" query to check that you are getting those 290 rows?
0

Try this,

Update Workorders
set prebookCB = 1
where CustomerID in (select customerid from customers 
where customeerstatus='Good-Prebook')

In this, the UPDATE works on you desired table. WHERE filters the records to update by comparing the customerID to be present in the result of a subquery. The subquery, further filters and select customerID from the customers table only when they have the apt status.

Hope this helps to explain !

5 Comments

How this answer differ from rakeshjain's answer
Foe some reason 0 rows are affected but I know that 290 customers have the CustomerStatus of 'Good - Prebook'. What else could be affecting it?
@PraveenPrasannan , I was typing, when the answer was posted, so did not know.
@user2120901 , well I can't directly point out the problem as I don't have the defining structures of your tables. On the other hand, try and confirm the Integrity and equivalence of the customerID attribute. The customerID shoulld also be present equivalently in the workorders table. If you can, give more details of your tables structure.
If I remove the last line, WHERE CustomerStatus ='Good-Prebook', then it updates all 6,000 records so I know the CustomerID is matching.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.