您好,欢迎来到99网。
搜索
您的当前位置:首页SQLServer通过储存过程实现批量删除注意事项

SQLServer通过储存过程实现批量删除注意事项

来源:99网


这里设定传过来的参数是拼接好的字符串,如:1,2,3,4,5 create procedure up_batchDeleteById ( @condition varchar(max) ) as delete from dt_name where id in(@condition) 以上的做法看似正确,实际会报错,具体原因是说id是int类型的,而@condition是字


这里设定传过来的参数是拼接好的字符串,如:1,2,3,4,5

create procedure up_batchDeleteById

(

@condition varchar(max)

)

as

delete from dt_name where id in(@condition)

以上的做法看似正确,实际会报错,具体原因是说id是int类型的,而@condition是字符串类型,这样无法删除

正确做法:

create procedure up_batchDeleteById

(

@condition varchar(max)

)

as

declare @sql varchar(max)

set @sql='delete from dt_name where id in (' + @condition + ')'

exec(@sql)

Copyright © 2019- 99spj.com 版权所有 湘ICP备2022005869号-5

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务