万能的批量删除过程

go---创建万能批量删除

drop proc dele
go
create proc dele
@TableName varchar(50),
@Id varchar(5000),
@IdName varchar(20)
as
begin
declare @strSql varchar(5000)


declare @sql varchar(4000)

set @sql='select col='''+ replace(@Id,',',''' union all select ''')+''''

if OBJECT_ID('tempdb..#DelID') is not null
drop table #DelID
create table #DelID(ID VARCHAR(36))

insert into #DelID exec(@sql)

set @strSql = 'delete from '+@TableName+' where '+@IdName+' in ( select ID from #DelID)'

exec(@strSql)
end

posted @ 2018-07-28 11:31  清风不在已徐来  阅读(195)  评论(1编辑  收藏  举报