在另一个存储中调用存储过程 [英] calling stored procedure in another stored

查看:94
本文介绍了在另一个存储中调用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有两个具有相同输入的存储过程,该输入包含(datefrom,dateto和accountId).第一个存储过程根据从from到到之间的日期返回数据,第二个存储过程根据在datefrom之前的日期返回数据.
现在,我要输入所有这些输入,并调用存储在第一个存储过程中的第二个存储.任何人都可以在这方面帮助我.拜托???
谢谢alot

Hi all,
I have two stored procedures that have the same input, the input contains (datefrom,dateto and accountId). The first stored procedure returns data according to date between from and to and the second stored procedure returns the data according to before the datefrom.
I want now to enter all these inputs and call the stored second stored in the first stored procedure. can any body help me in that. Please????
thanks alot

推荐答案

只需使用EXEC关键字.有关详细信息,请参见下面的文章:
http://www.aspfree.com/c/a/ASP.NET-Code/Call-Stored-procedure-from-in-other-stored-procedure-return-values/ [
Simply use the EXEC keyword. See article below for detail:
http://www.aspfree.com/c/a/ASP.NET-Code/Call-Stored-procedure-from-within-another-stored-procedure-return-values/[^]


您是说要向第二个存储过程传递几个值吗?如果是这种情况,请查看例如本文如何将多个记录传递到存储过程 [ ^ ].

在本文中,调用端是一个客户端,但它也可以是另一个存储过程.重点是传递未知数量的值.
Do you mean you want to pass several values to the second stored procedure. If that''s the case, have a look at for example this article How to pass multiple records to a Stored Procedure[^].

In the article the calling end is a client but it could also be another stored procedure. The main point is to pass an unknown amount of values.


您是否要将两个存储过程的结果合并为一个结果?然后试试这个
Do you want to merge the result of the two stored procedures into a single result? Then try this
-- create temporary table to store the result
IF OBJECT_ID('tempdb..#result')
   DROP TABLE #result
CREATE TABLE #result
   (
   datefrom  DATETIME NULL,
   dateto    DATETIME NULL,
   accountId INT      NULL
   )

-- insert from first proc
-- NOTE columns must in the same order as the proc result
INSERT INTO #result
   (
   datefrom,
   dateto,
   accountId
   )
EXEC firstProcedure @param1,@param2 -- replace with your procedure name and parameters

-- insert from second proc
-- NOTE columns must in the same order as the proc result
INSERT INTO #result
   (
   datefrom,
   dateto,
   accountId
   )
EXEC secondProcedure @param1,@param2 -- replace with your procedure name and parameters

-- final result
SELECT  *
FROM    #result


这篇关于在另一个存储中调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆