富贵资源网 Design By www.hznty.com
复制代码 代码如下:
Create PROCEDURE Batch_Delete
@TableName nvarchar(100), --表名
@FieldName nvarchar(100), --删除字段名
@DelCharIndexID nvarchar(1000)
as
DECLARE @PointerPrev int
DECLARE @PointerCurr int
DECLARE @TId NVARCHAR(50), @sql NVARCHAR(1000)

Set @PointerPrev = 1
while (@PointerPrev < LEN(@DelCharIndexID))
Begin
Set @PointerCurr = CharIndex(',',@DelCharIndexID,@PointerPrev)
if(@PointerCurr>0)
Begin
SET @TId = cast(SUBSTRING(@DelCharIndexID, @PointerPrev, @PointerCurr - @PointerPrev) As NVARCHAR(50))
SET @sql = 'Delete From '+ @TableName +' Where '+ @FieldName + ' = '''+ @TID+''''
Exec(@Sql)
Print('======='+@TId+'=======sql'+@Sql)
SET @PointerPrev = @PointerCurr + 1
Print(@PointerPrev)
End
else
Begin
Print('break')
Break
End
End
--删除最后一个,因为最后一个后面没有逗号,所以在循环中跳出,需另外再删除
SET @TId = cast(SUBSTRING(@DelCharIndexID, @PointerPrev, LEN(@DelCharIndexID) - @PointerPrev + 1) As NVARCHAR(50))
SET @sql = 'Delete From '+ @TableName +' Where '+ @FieldName + ' = '''+ @TID+''''
Exec(@Sql)
Print('======='+@TId+'=======sql'+@Sql)
GO
富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com