当前,我正在SQL Server中使用T-SQL编写存储过程。我的脚本包含运行另一个存储过程以从表中获取数据列表的代码。我想操纵数据,使用数据列表将其修改以用于存储过程中的其他目的(例如,汇总一列并添加更多数据列表)。我知道的一种方法是创建一个临时表。但是之后,我不太确定。请帮忙。谢谢。
这是我的代码:
ALTER PROCEDURE [dbo].[AJU_Rpt_ARAgingSp]
(@Slsman_Starting slsmantype = NULL,
@Slsman_Ending slsmantype = NULL,
@Custnum_Starting custnumtype = NULL,
@Custnum_Ending custnumtype = NULL,
@CustType endusertypetype = NULL,
@CutOff_Date datetype = NULL,
@SumToCorp ListYesNoType = NULL, -- >> 0 = individual, 1 = corp customer
@ShowActive ListYesNoType = NULL, -- >> 0 = all trx, 1 = active only
@TransDomCurr ListYesNoType = NULL, -- >> 0 = dont convert, 1 = convert to local currency
@AgingBasis ArAgeByType = NULL, -->> i = invoice date, d = due date
@LeftToRight ListYesNoType = NULL, -- >> 0 = right to left, 1 = left to right
@CurrSite NVARCHAR(8),
@ShowDetailInfo NVARCHAR(1) = NULL)
AS
BEGIN
SET NOCOUNT ON
IF ISNULL(@CurrSite ,'') = ''
SET @CurrSite = (SELECT TOP 1 site_ref FROM parms_mst)
DECLARE @v_StartDate DateType
SET @Slsman_Starting = ISNULL(@Slsman_Starting, dbo.LowCharacter())
SET @Slsman_Ending = ISNULL(@Slsman_Ending, dbo.HighCharacter())
SET @Custnum_Starting = ISNULL(@Custnum_Starting, dbo.LowCharacter())
SET @Custnum_Ending = ISNULL(@Custnum_Ending, dbo.HighCharacter())
SET @v_StartDate = dbo.LowDate()
SET @CutOff_Date = GETDATE()
EXEC dbo.ApplyDateOffsetSp @v_StartDate OUT, NULL, 0
EXEC AJU_Rpt_DebtorSp
@CustNumStart = @Custnum_Starting
,@CustNumEnd = @Custnum_Ending
,@DistDateStart = @v_StartDate
,@DistDateEnd = @CutOff_Date
,@CurrCodeStart = NULL
,@CurrCodeEnd = NULL
,@SlsmanStart = @Slsman_Starting
,@SlsmanEnd = @Slsman_Ending
,@TerritoryStart = NULL
,@TerritoryEnd = NULL
,@CustTypeStart = NULL
,@CustTypeEnd = NULL
,@SiteGroup = @CurrSite
,@ConsolidatePayment = NULL
,@DisplayResult = 1
END
答案 0 :(得分:0)
由于临时需要初始结果表,因此您可以执行以下操作:
在调用过程中编写如下语句:
INSERT INTO @_Tempo_Table
EXEC Invoked_Procedure (<params>) ;
在调用的过程中发出SELECT
,它将返回记录集。
另一方面,如果您需要将初始表传递给被调用的过程:
READONLY
)此方法将提供最佳性能(这里我假设您不传递包含数百万条记录的表;如果这样做,它仍然是最快的方法,尽管您可能需要很多内存)。 / p>