zoukankan      html  css  js  c++  java
  • SQL Server--一个存储过程对同一个字段执行两种Update

    需求:

    服务器程序被界面点击“置零”按钮后,所有未完成的任务的状态都置为异常结束。

    但分两种情况:

    1. 0<=Status<40状态为未完成的任务1,其异常结束状态为50
    2. 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
  • 相关阅读:
    matlab cell
    matlab linux 快捷键设置——有问题还是要解决
    latex 小结
    TOJ 1258 Very Simple Counting
    TOJ 2888 Pearls
    HDU 1248 寒冰王座
    TOJ 3486 Divisibility
    TOJ 3635 过山车
    TOJ 1840 Jack Straws
    HDU 4460 Friend Chains
  • 原文地址:https://www.cnblogs.com/zwh1993/p/12449368.html
Copyright © 2011-2022 走看看