![](/img/trans.png)
[英]SQL stored procedure; using input parameter to call another stored proc
[英]Main Stored Procedure to Execute another Proc depending on Input and output in a CSV
我有两个基本给出表输出的过程。 我有第三个过程,基本上调用了这两个过程,并以csv文件格式给出输出。
任何人都可以帮助我以正确的方式进行构建。 以下是我正在尝试做的事情:
这两个过程中的每一个都给出大约10万行的输出,我想捕获该输出并想从Main过程中的csv文件中给出输出(请告诉我是否需要更多信息)
Create PROC MAIN
@InputParam int
AS
Begin
Set NOCOUNT ON;
BEGIN TRY
IF @InputParam not in (1,2)
BEGIN
Print 'Error Message'
END
Else
begin
IF @InputParam=1
BEGIN
Exec StoredProc1
Print 'Stored Procedure StoredProc1 ended at '+Convert(Varchar(25),GETDATE(),21);
End
Else
Begin
Print 'StoredProc1 does not exist'
END
IF @InputParam=2
BEGIN
Exec StoredProc2
Print 'Stored Procedure StoredProc2 ended at '+Convert(Varchar(25),GETDATE(),21);
End
Else
BEGIN
Print 'StoredProc2 does not exist'
END
END -- This is END for ELSE loop
END TRY
Begin Catch
Print 'Input Validation Catch Block with # '+ Convert(Varchar(5),ERROR_NUMBER())+' Msg: '+ERROR_MESSAGE();
End Catch
END
您可能想尝试的是在主存储过程中声明一个表vairable。 该表需要与子过程的输出完全匹配。 语法为:
DECLARE @Temp TABLE(
Filed1 INT,
Field2 VARCHAR(100),
etc
)
然后,您可以执行子存储过程并将其插入您定义的表中,如下所示:
INSERT INTO @Temp
EXEC StoredProc1
最后,从@Temp中选择
SELECT * FROM @Temp
显然,您将需要满足您的确切要求,但是我希望它可以为您提供帮助
没有某种形式的代码,您不能直接从存储过程输出到CSV,因此这实际上取决于您要开发的内容(即称为存储过程的东西)。 您也许可以构建一个SQL作业以输出到CSV。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.