zoukankan      html  css  js  c++  java
  • 存储过程 批量删除记录

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[XTJ_NewsInfor_DeleteArray]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
    drop procedure [dbo].[XTJ_NewsInfor_DeleteArray]
    GO
    ------------------------------------
    --用途:根据id字符串删除所有的记录
    --项目名称:
    --说明:
    --时间:2008-8-13 14:44:20
    ------------------------------------
    CREATE PROCEDURE XTJ_NewsInfor_DeleteArray
        @ID nvarchar(1000)
    as
        DECLARE @PointerPrev int
        DECLARE @PointerCurr int
        DECLARE @TId int
        Set @PointerPrev=1
        
        while (@PointerPrev < LEN(@ID))
        Begin
            Set @PointerCurr=CharIndex(',',@ID,@PointerPrev)
            if(@PointerCurr>0)
            Begin
                set @TId=cast(SUBSTRING(@ID,@PointerPrev,@PointerCurr-@PointerPrev) as int)
                Delete from XTJ_NewsInfor where ID=@TID
                SET @PointerPrev = @PointerCurr+1
            End
            else
                Break
        End
        --删除最后一个,因为最后一个后面没有逗号,所以在循环中跳出,需另外再删除
         set @TId=cast(SUBSTRING(@ID,@PointerPrev,LEN(@ID)-@PointerPrev+1) as int) 
         Delete from XTJ_NewsInfor where ID=@TID
    GO

    下来要批量删除记录的话只要给存储过程传参1,2,3,4,……n,存储过程就会删除相应的记录

  • 相关阅读:
    BZOJ 4815: [Cqoi2017]小Q的表格
    BZOJ 3676: [Apio2014]回文串
    BZOJ 4503: 两个串
    BZOJ 2618: [Cqoi2006]凸多边形
    BZOJ 1137: [POI2009]Wsp 岛屿
    BZOJ 4824: [Cqoi2017]老C的键盘
    BZOJ 3167: [Heoi2013]Sao
    BZOJ 4033: [HAOI2015]树上染色
    1003. 我要通过!(20)
    1002. 写出这个数 (20)
  • 原文地址:https://www.cnblogs.com/luluping/p/1530506.html
Copyright © 2011-2022 走看看