
正文
SQL Server--一个存储过程对同一个字段执行两种Update
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
需求:
服务器程序被界面点击“置零”按钮后,所有未完成的任务的状态都置为异常结束。
但分两种情况:
- 0<=Status<40状态为未完成的任务1,其异常结束状态为50
- 60<=Status<100状态为未完成的任务2,其异常结束状态为110
写在数据库的同一个存储过程中完成,主题为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 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







