存储过程中如何设置返回值,另外一个存储过程又如何调用该返回值,详情请看。。。

yesjoy 2005-12-30 10:44:21
--说明:这个存储过程中查询出xhbh字段的值(可能为0、1、或者多个)然后返回给pro2做为xxflbh in()括号内的条件
--比如执行完pro1后结果如下:
xhbh
106D96C39BDca1C72349
1065283BDB690F98317C
105C75EBFC636109F0BD
那么在pro2中调用pro1返回的结果后组成的sql语句应该是这样的:
delete from bd_sbsxbjg where cjbh=(select cjbh from bd_zzcj where cjmc=@param1)
and xxflbh in('106D96C39BDca1C72349','1065283BDB690F98317C','105C75EBFC636109F0BD')

--有返回值的存储过程
create procedure pro1
@param1 varchar(100),@param2 varchar(100)
as
select xhbh from bd_sccjxh
where tname in(select tname from bd_sccjxh where cjbh=(select cjbh from bd_zzcj where cjmc = @param1)
and xhbh in(select xhbh from bd_sccjxh where cjbh=(select cjbh from bd_zzcj where cjmc = @param2))
and xhbh in(select xhbh from bd_sccjxh where cjbh=(select cjbh from bd_zzcj where cjmc = @param1)))
GO

--调用存储过程pro1
CREATE procedure pro2
@param1 varchar(100),@param2 varchar(100)
as
delete from bd_sbsxbjg where cjbh=(select cjbh from bd_zzcj where cjmc=@param1)
and xxflbh in()

不知道问题是否已经说明白
...全文
85 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
pbsql 2005-12-30
  • 打赏
  • 举报
回复
改存储过程pro2:
CREATE procedure pro2
@param1 varchar(100),@param2 varchar(100)
as
create table #t(xhbh varchar(20))
insert into #t(xhbh) exec pro1 参数1,参数2
delete from bd_sbsxbjg where cjbh=(select cjbh from bd_zzcj where cjmc=@param1)
and xxflbh in(select xhbh from #t)
drop table #t
wangxin_ch 2005-12-30
  • 打赏
  • 举报
回复
谢谢各位

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧