首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

批量删除记录的存储过程写法?解决思路

2012-01-26 
批量删除记录的存储过程写法?在程序里面用了个全选按钮,循环遍历把要删除的记录编号拼接在一起(不想遍历一

批量删除记录的存储过程写法?
在程序里面用了个全选按钮,循环遍历把要删除的记录编号拼接在一起(不想遍历一个删除一个,那样效率太低了),准备把这个字符串当成一个参数传到存储过程里面,请教怎么写这个存储过程才能删除这些记录?

[解决办法]
将编号已“,”号分割作为存储过程的参数传进去
然后使用自带的函数写个象ASP中的SPLIT函数的用法
应该可以
[解决办法]
create table T(id int)
insert T select 1
union all select 2
union all select 3
union all select 4
union all select 5

create proc pc(@id varchar(20))
as
exec( 'delete T where id in( '+@id+ ') ')
go


exec pc '2,3 '

select * from T

--result
id
-----------
1
4
5

(3 row(s) affected)

热点排行