• 存储过程批量删除


    今天闲来无事,把批量删除由代码删除 改成存储过程删除 

    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER procedure [dbo].[pr_deletepackage]--------套餐批量删除 
    (
    @ids nvarchar(100) --参数 (1,2,3,)
    )
    as
    declare @temp table(a varchar(100))--创建临时表
    --------把参数@ids分割成int数组 判断是否满足删除条件
    declare @n Int
    declare @lid int--临时ID
    declare @count int --判断是否使用
    declare @sercount int --判断该产品下是否存在服务
    set @ids=RTRIM(LTRIM(@ids))
    set @n=CHARINDEX(',',@ids)
    while @n>=1
    begin
     set @lid=Left(@ids,@n-1) --截取当前ID
     set @count= (select COUNT(*) from t_order_package  where pi_id=@lid) --判断当前服务是否已经被使用
     set @sercount=(select COUNT(*) from t_package_service where pi_packageid=(select pi_packageid  from t_packages_info where pi_id=@lid)) --判断当前套餐下是否存在服务
     print @count
     print @sercount
     if (@count=0 and @sercount=0) --当前套餐没有使用 且 没有 服务的情况下 将id 插入临时表
     begin
     Insert @temp Values(@lid)
     end
     Set @ids = SubString(@ids,@n+1,Len(@ids)-@n)
     Set @n = CharIndex(',',@ids)
    end
    if @ids<>''
    update t_packages_info set pi_status=-1 where pi_id in(select * from @temp)  --删除 临时表里的id

    最后一个id后 必须加, 号! 存储过程一直是我的弱项,多写写 没坏处!

  • 相关阅读:
    k8s查看证书期限
    Calico 路由反射模式权威指南
    prometheus 数据传输到远程 VictoriaMetrics 存储
    node cnmp 安装
    redis3.2.8 版本部署 哨兵模式
    Centos搭建ffmpeg环境
    查看k8s controllersmanager scheduler 主
    监控rocketmq 常用方法
    apache 负载均衡http 配置
    JBoss AS 安装配置部署报错以及使用wildfly替换
  • 原文地址:https://www.cnblogs.com/zplvpp520/p/6908550.html
Copyright © 2020-2023  润新知