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,存储过程就会删除相应的记录

  • 相关阅读:
    api接口统一管理
    axios封装
    事件监听和事件模型
    W3C标准
    Redis安装(PHPredis服务+windows的redis环境)
    Redis介绍
    jQuery ajax方法小结
    博客园鼠标特效
    PHP---截取七牛地址中的文件名
    jQuery---显示和隐藏
  • 原文地址:https://www.cnblogs.com/luluping/p/1530506.html
Copyright © 2011-2022 走看看