[英]How to union all the result of two stored procedure?
I have two stored procedure which returns something like this: 我有两个存储过程,返回的内容如下:
call proc1('Jack');
+------+------------+
| 3232 | Admin |
+------+------------+
| 3254 | SuperUser |
+------+------------+
| 3264 | Admin |
+------+------------+
call proc2('Martin');
+------+--------+
| 6345 | User |
+------+--------+
| 6309 | Stuff |
+------+--------+
How can I use combine the result of those two procedure and use the final result? 如何结合使用这两个过程的结果并使用最终结果?
I would suggest you, You can create the new procedure and invoke both procedure proc1 and proc2 inside the new procedure and also perform union operation inside new procedure by creating a temparory table. 我建议您,您可以创建新过程并在新过程中调用过程proc1和proc2,还可以通过创建临时表在新过程中执行联合操作。 for example: 例如:
create Procedure get_union_proc(your_parameter ...)
BEGIN
Insert INTO #Temp_table1 exec proc1;
Insert INTO #Temp_rable2 exec proc2;
select * from Temp_table1
union
select * from Temp_table2
END get_union_proc
I hope it would be helpful. 希望对您有所帮助。
You Need to create a temporary table and fetch results from the temporary table. 您需要创建一个临时表并从该临时表中获取结果。
INSERT INTO #TempTable
EXEC StoredProc0;
INSERT INTO #TempTable
EXEC Storedproc1;
Select * from TempTable; 从TempTable中选择*;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.