Update PO status by SQL query

拟墨画扇 提交于 2021-02-17 07:04:10

问题


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';

error message

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!