sql 저장 프로 세 스 데이터 일괄 삭제 문

 
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

좋은 웹페이지 즐겨찾기