if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[XTJ_NewsInfor_DeleteArray]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[XTJ_NewsInfor_DeleteArray]
GO
------------------------------------
--用途:根据id字符串删除所有的记录
--项目名称:
--说明:
--时间:2008-8-13 14:44:20
------------------------------------
CREATE PROCEDURE XTJ_NewsInfor_DeleteArray
@ID nvarchar(1000)
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 XTJ_NewsInfor where ID=@TID
SET @PointerPrev = @PointerCurr+1
End
else
Break
End
--删除最后一个,因为最后一个后面没有逗号,所以在循环中跳出,需另外再删除
set @TId=cast(SUBSTRING(@ID,@PointerPrev,LEN(@ID)-@PointerPrev+1) as int)
Delete from XTJ_NewsInfor where ID=@TID
GO
下来要批量删除记录的话只要给存储过程传参1,2,3,4,……n,存储过程就会删除相应的记录