问题
I am trying to update the PO status from 'r' to 'c'
Below is the extraction query.
update purchase_order
set status = 'c'
where STATUS = 'r' and order_date < '2019-01-01';
It was ok to update but now it appears the error message. I wonder what happened?
回答1:
Assuming the example select
gives all of the rows you want to change and none of the rows you don't:
update purchase_order
set status = 'c'
where STATUS = 'r' and order_date < '2020-01-01';
You have to do this in a separate statement from the select
query.
回答2:
SSMS will default to the master
table. There are settings to change that, but I suspect in this case, your problem is that the query is not being run against the correct database.
You can change the database from master
to the correct one using the SSMS UI (there's a drop down to select the database the query runs against), OR, incorporate a USE
statement with your query:
USE [database_name]
GO
UPDATE PURCH_ORDER_LINE
SET [status] = 'c'
WHERE [status] = 'r' and order_date < '2019-01-01'
GO
来源:https://stackoverflow.com/questions/65956422/update-po-status-by-sql-query