简体   繁体   English

存储过程将结果返回到另一个存储过程的temp表中

[英]Stored procedure return results into temp table in another stored procedure

What I want to do is insert new transaction that is a copy of the latest transaction but change couple of the values. 我要执行的操作是插入新事务,该事务是最新事务的副本,但更改几个值。

I have SP that returning the latest transaction given the request id called sp_Get_YellowCard_Request_Last_Transaction 我有SP返回给定的请求ID称为sp_Get_YellowCard_Request_Last_Transaction的最新交易

I have another SP that I want to use the above called sp_Update_CC_Move_YCR_TO . 我还有一个我想使用上述名称的sp_Update_CC_Move_YCR_TO

But since the sp_Get_YellowCard_Request_Last_Transaction returns a lot of fields (26) I don't want to specify all of them and just insert the result of it into temporary table and later change some field, and finally insert the temp table into the destination transaction table. 但是由于sp_Get_YellowCard_Request_Last_Transaction返回很多字段(26),所以我不想指定所有字段,而只是将其结果插入临时表中,然后更改某些字段,最后将临时表插入目标事务表中。

what i'v writter so far is: 到目前为止,我编写的是:

USE [YellowCard_NewDesign]
GO
/****** Object:  StoredProcedure [dbo].[sp_Update_CC_Move_YCR_TO]    Script Date: 02/26/2013 09:43:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_Update_CC_Move_YCR_TO]
    @YellowCard_Request_ID int,
    @yc_changer_username nvarchar(MAX),
    @yc_changer_rolename nvarchar(MAX),
    @yc_new_status nvarchar(MAX)
AS
    INSERT INTO #last_transaction
    EXEC dbo.sp_Get_YellowCard_Request_Last_Transaction @YellowCard_Request_ID*

I'm getting an error that #last_transaction is not defined. 我收到未定义#last_transaction的错误。

How can I complete my SP without defining the temporary table fields? 如何在不定义临时表字段的情况下完成SP?

In SQL Server 2000, I used the following trick: 在SQL Server 2000中,我使用了以下技巧:

IF OBJECT_ID('tempdb..#last_transaction') IS NULL
    CREATE TABLE #last_transaction(
        ....
    )

INSERT INTO #last_transaction
    EXEC ...

For later versions of SQL Server, I'd prefer table-valued functions. 对于更高版本的SQL Server,我希望使用表值函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM