• 存储过程里循环读取Array




    CREATE PROCEDURE dbo.s_Manager_UpdateManagerInCatalogID
    (
     @catalogIDArray nvarchar(512),
     @managerID int,
     @Message nvarchar(64) out
    )
    AS

     DECLARE @PointerPrev int
         DECLARE @PointerCurr int
         DECLARE @TId int
         Set @PointerPrev=1
         set @PointerCurr=1

     begin transaction

     Set NoCount ON
     DELETE FROM Common_ManagerINCatalogs where ManagerID = @ManagerID--删除以前的记录
        
         Set @PointerCurr=CharIndex(',',@catalogIDArray,@PointerPrev+1)
         set @TId=cast(SUBSTRING(@catalogIDArray,@PointerPrev,@PointerCurr-@PointerPrev) as int)

         Insert into Common_ManagerINCatalogs (ManagerID,CatalogID) Values(@ManagerID,@TId)

         SET @PointerPrev = @PointerCurr
         while (@PointerPrev+1 < LEN(@catalogIDArray))
         Begin
             Set @PointerCurr=CharIndex(',',@catalogIDArray,@PointerPrev+1) --假设已“,”分隔
             if(@PointerCurr>0)
             Begin
                 set @TId=cast(SUBSTRING(@catalogIDArray,@PointerPrev+1,@PointerCurr-@PointerPrev-1) as int)
                  Insert into Common_ManagerINCatalogs (ManagerID,CatalogID) Values(@ManagerID,@TId)
                 SET @PointerPrev = @PointerCurr
             End
             else
                 Break
         End
        
         set @TId=cast(SUBSTRING(@catalogIDArray,@PointerPrev+1,LEN(@catalogIDArray)-@PointerPrev) as int)
        Insert into Common_ManagerINCatalogs (ManagerID,CatalogID) Values(@ManagerID,@TId)
         Set NoCount OFF
         if @@error=0
         begin
             commit transaction
         end
         else
         begin
       rollback transaction
         end

      SELECT @Message = '{Success}'

    GO

  • 相关阅读:
    WPF 复制和粘贴
    WPF控件模拟双击事件
    WPF获取鼠标当前位置
    user32.dll
    C# 根据IP地址获取城市
    WPF 动态布局Grid
    手机自动化测试:Appium源码分析之跟踪代码分析五
    手机自动化测试:appium源码分析之bootstrap三
    手机自动化测试:appium源码分析之bootstrap二
    手机自动化测试:appium源码分析之bootstrap一
  • 原文地址:https://www.cnblogs.com/smallmuda/p/302698.html
Copyright © 2020-2023  润新知