新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
通過SQL Server存儲(chǔ)過程傳送數(shù)組參數(shù)刪除多條記錄
下面為您介紹的SQL Server刪除方法和一般的SQL Server刪除方法有所不同,該方法實(shí)現(xiàn)的是在SQL Server存儲(chǔ)過程通過傳送數(shù)組字符串參數(shù)SQL Server刪除多條記錄(如多選或全選表單中的多選框所獲取的一組數(shù)值刪除 )。

- CREATE PROCEDURE DeleteNews
- @ID nvarchar(500)
- 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 News where ID=@TID
- SET @PointerPrev = @PointerCurr+1
- End
- else
- Break
- End
- --刪除最后一個(gè),因?yàn)樽詈笠粋€(gè)后面沒有逗號(hào),所以在循環(huán)中跳出,需另外再刪除
- set @TId=cast(SUBSTRING(@ID,@PointerPrev,LEN(@ID)-@PointerPrev+1) as int)
- Delete from News where ID=@TID
- GO
- set ANSI_NULLS ON
- set QUOTED_IDENTIFIER ON
- GO
- CREATE PROCEDURE AddInter
- @userID nvarchar(max),
- @ProjecID int
- as
- begin
- DECLARE @PointerPrev int
- DECLARE @PointerCurr int
- DECLARE @TId int
- Set @PointerPrev=1
- begin transaction
- while (@PointerPrev < LEN(@userID))
- Begin
- Set @PointerCurr=CharIndex(',',@userID,@PointerPrev)
- if(@PointerCurr>0)
- Begin
- set @TId=cast(SUBSTRING(@userID,@PointerPrev,@PointerCurr-@PointerPrev) as int)
- exec AddIntention @TID,@ProjecID,0,2
- SET @PointerPrev = @PointerCurr+1
- End
- else
- Break
- End
- --刪除最后一個(gè),因?yàn)樽詈笠粋€(gè)后面沒有逗號(hào),所以在循環(huán)中跳出,需另外再刪除
- set @TId=cast(SUBSTRING(@userID,@PointerPrev,LEN(@userID)-@PointerPrev+1) as int)
- exec AddIntention @TID,@ProjecID,0,2
- IF (@@error <> 0)
- begin
- ROLLBACK TRANSACTION
- end
- COMMIT TRANSACTION
- Return
- end
- GO
【編輯推薦】
六種SQL Server刪除重復(fù)行的方法
SQL Server創(chuàng)建表語(yǔ)句介紹
SQL Server創(chuàng)建數(shù)據(jù)庫(kù)的命令
sql server系統(tǒng)表?yè)p壞的解決方法
帶您了解SQL Server游標(biāo)
網(wǎng)頁(yè)標(biāo)題:通過SQL Server存儲(chǔ)過程傳送數(shù)組參數(shù)刪除多條記錄
分享路徑:http://www.dlmjj.cn/article/dhieghh.html


咨詢
建站咨詢
