sybase存储过程问题 :问: SYBASE存储过程,为什么执行到这一句就不执行了
select @nSerialNo = serialno from schedule where phonenum= @strPhoneNum and type = @nType
if @@rowcount = 0
begin
...
end
else
begin
...
end
上面的select结果是空记录集,存储过程一执行到空记录集,就会返回?
答:if exists(select @nSerialNo = serialno from schedule where phonenum= @strPhoneNum and type = @nType)这个语句的逻辑有点问题?
if exists 一般是用来确定是否存在类似的记录?你现在又要将存在的结果赋值?其实还不如写 if exists(select 1 from schedule where phonenum= @strPhoneNum and type = @nType)
确定是否存在这样的记录,在执行相应的处理。
select @nSerialNo = serialno from schedule where phonenum= @strPhoneNum and type = @nType
if @@rowcount = 0
begin
...
end
else
begin
...
end
上面的select结果是空记录集,存储过程一执行到空记录集,就会返回?
答:if exists(select @nSerialNo = serialno from schedule where phonenum= @strPhoneNum and type = @nType)这个语句的逻辑有点问题?
if exists 一般是用来确定是否存在类似的记录?你现在又要将存在的结果赋值?其实还不如写 if exists(select 1 from schedule where phonenum= @strPhoneNum and type = @nType)
确定是否存在这样的记录,在执行相应的处理。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-122695/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10294527/viewspace-122695/
Sybase存储过程问题解析
本文探讨了Sybase存储过程中遇到的问题,特别是当查询结果为空记录集时的处理方式。提出了使用if exists语句改进代码逻辑的方法,以更有效地判断记录是否存在。
6964

被折叠的 条评论
为什么被折叠?



