青阳论坛招聘信息网:存储过程中字符串连接的问题

来源:百度文库 编辑:杭州交通信息网 时间:2024/03/29 10:25:34
存储过程
CREATE procedure deletedata
as
declare @int_toolid int
declare Total_cursor cursor for
select int_toolid from telttoo_inf where vc_place like '%运维部%'
open Total_cursor
fetch next from Total_cursor into @int_toolid
while(@@fetch_status=0)
begin
delete from telttool_status where int_toolid=@int_toolid
delete from telttool_rec where int_toolid like '%'+@int_toolid+'%'(错误语句)
delete from telttool_history where int_toolid=@int_toolid
delete from telttool_check where int_toolid=@int_toolid
fetch next from Total_cursor into @int_toolid
end
delete from telttoo_inf where vc_place like '%运维部%'
close Total_cursor
deallocate Total_cursor
GO
测试语法通过,但在执行时其错误为“将 varchar 值 '%' 转换为数据类型为 int 的列时发生语法错误”。
然后我将相关语句改为:delete from telttool_rec where int_toolid like '%'+convert(varchar(4),@int_toolid)+'%'后语法检测通过,且执行时并没有错误产生,但执行后却发现telttool_rec 中的信息并没有像我想象中的被删掉,不知道由于什么原因,请求帮助!

我也在学存储过程,但是解决不了您的问题,不好意思哈。