我们如何将两个不同的结果从一个SP保存到两个不同的表中 [英] How we saving two different result from one SP into two different table

查看:96
本文介绍了我们如何将两个不同的结果从一个SP保存到两个不同的表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi



我有一个SpPROCS.abc给出两个不同的结果集,我们需要通过调用另一个SP示例将它们保存在两个不同的表中PROCS.abcd。



我尝试了什么:



可能是我没试过

我有一个SpPROCS.abc给出了两个不同的结果集,我们需要通过调用另一个SP示例PROCS.abcd将它们保存在两个不同的表中。

hi

I have one Sp "PROCS.abc" which Give two different Result Set , we need to save them in two Different tables by calling another SP example PROCS.abcd.

What I have tried:

Probably i not tried
I have one Sp "PROCS.abc" which Give two different Result Set , we need to save them in two Different tables by calling another SP example PROCS.abcd.

推荐答案

您无法在T-SQL中访问单独的结果集。



您可以在代码中执行此操作,例如:将结果返回到.NET DataSet,您将能够访问这些表。示例如何:执行存储过程返回多个结果集 [ ^ ]



如果两个结果集具有相同的模式,那么您可以将所有输出保存到临时文件中,然后根据您想要的任何条件将数据拆分出来。示例:

You can't access the separate result sets in T-SQL.

You can do it in code e.g. Return the results to a .NET DataSet and you will be able to access the tables. Example How to: Execute Stored Procedures Returning Multiple Result Sets[^]

If both result sets have the same schema then you can save all of the output into a temporary file and then split the data out based on whatever criteria you want Example:
CREATE PROCEDURE [dbo].[sp_TwoResults]
AS
 
BEGIN
	SELECT 'table', TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
	SELECT 'column', COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
END
GO

CREATE TABLE #temp(ObjectType varchar(6), ObjectName Varchar(50))
INSERT INTO #temp
EXEC sp_TwoResults
select * from #temp





最好是改变存储过程以将输出直接放入th e目标表或有两个存储过程 - 存储过程和T-SQL中的多个结果集 [ ^ ]


这篇关于我们如何将两个不同的结果从一个SP保存到两个不同的表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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