【问题标题】:Temp table from two functions into a pivot table将两个函数的临时表转换为数据透视表
【发布时间】:2013-09-19 17:53:27
【问题描述】:

我需要从两个函数创建一个数据透视表,因为其中涉及的记录数量,我想使用一个临时表。

SELECT [OrderNumber]
    ,[OrderName]
    ,[Code]
    ,[Amount1]
 INTO #TempPayment 
FROM [dbo].[fn_Reconciliation_PaymentByDateRange](@BeginDate,@EndDate) 

SELECT [OrderNumber]
    ,[OrderName]
    ,[Code]
    ,[Amount1]
 INTO #TempInvoice
FROM [dbo].[fn_Reconciliation_InvoiceByDateRange](@BeginDate,@EndDate) 

以上是我用来创建 2 个临时表的内容,但我想看看是否可以将其压缩为一个临时表。

这样做的最终结果是我需要能够拉出上面列出的“选择”部分,然后在Code 列上拉出pivot 它们。我可以处理,但我真的不想最终生成第三个临时表,但我想我最终可能需要。

【问题讨论】:

    标签: sql sql-server function pivot


    【解决方案1】:

    我自己想出来的。这里:

    SELECT [OrderNumber]
    ,[OrderName]
    ,[Code]
    ,[Amount1]
    INTO #TempCompilation
    FROM [dbo].[fn_Reconciliation_PaymentByDateRange](@BeginDate,@EndDate) 
    
    INSERT INTO #TempCompilation
    SELECT [OrderNumber]
    ,[OrderName]
    ,[Code]
    ,[Amount1]
    FROM [dbo].[fn_Reconciliation_InvoiceByDateRange](@BeginDate,@EndDate) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-25
      • 2015-07-21
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      相关资源
      最近更新 更多