需求:
服务器程序被界面点击“置零”按钮后,所有未完成的任务的状态都置为异常结束。
但分两种情况:
写在数据库的同一个存储过程中完成,主题为13-22行:
1 USE [HumidifyMachine] 2 GO 3 4 /****** Object: StoredProcedure [dbo].[sp_UpdateTaskEndWithException] Script Date: 2020/3/9 16:02:45 ******/ 5 SET ANSI_NULLS ON 6 GO 7 8 SET QUOTED_IDENTIFIER ON 9 GO 10 11 CREATE procedure [dbo].[sp_UpdateTaskEndWithException] 12 as 13 if exists(select * from T_Task where Status>=0 and Status<40) 14 begin 15 Update T_Task 16 set Status=50 where Status>=0 and Status<40 17 end 18 else if exists(select * from T_Task where Status>=60 and Status<100) 19 begin 20 Update T_Task 21 set Status=110 where Status>=60 and Status<100 22 end 23 GO
原文:https://www.cnblogs.com/zwh1993/p/12449368.html