0

我有这个要转换为 T-SQL 的 Access 查询:

TRANSFORM Sum(dbo.vw_SIMP_EN_F_Tx_AccRec_8.Outstanding) AS SumOfOutstanding
SELECT dbo.vw_SIMP_EN_F_Tx_AccRec_88.To_ICJ, q_F_TX_AccRec_8.From_Reference__c, 
       q_F_TX_AccRec_8.[From Account]
FROM dbo.vw_SIMP_EN_F_Tx_AccRec_8
GROUP BY dbo.vw_SIMP_EN_F_Tx_AccRec_8.To_ICJ, 
         dbo.vw_SIMP_EN_F_Tx_AccRec_8.From_Reference__c, 
         dbo.vw_SIMP_EN_F_Tx_AccRec_8.[From Account]
PIVOT dbo.vw_SIMP_EN_F_Tx_AccRec_8.Age 
  In ("Current","30 days","60 days","90 days");

到目前为止,我已经在 T-SQL 中做到了这一点:

SELECT [To_ICJ],
   [From_Reference__c],
   [From Account],
   [Current],
   [30 days],
   [60 days],
   [90 days]
FROM
(Select Sum(dbo.vw_SIMP_EN_F_Tx_AccRec_8.[Outstanding]) AS [SumOfOutstanding],
    dbo.vw_SIMP_EN_F_Tx_AccRec_8.Age AS [PIVOT_ITEM]
FROM dbo.vw_SIMP_EN_F_Tx_AccRec_8
GROUP BY [To_ICJ],
     [From_Reference__c],
     [From Account],
     Age) AS p PIVOT(
     Sum([SumOfOutstanding]) FOR [PIVOT_ITEM]
 In ([Current],[30 days],[60 days],[90 days])) as pvt

但是我的 T-SQL 导致了这些错误:

消息 207,级别 16,状态 1,第 1 行
无效的列名称“To_ICJ”。

消息 207,级别 16,状态 1,第 2 行
无效的列名称“From_Reference__c”。

消息 207,级别 16,状态 1,第 3 行
无效的列名称“来自帐户”。

知道我做错了什么吗?

4

1 回答 1

2

您在子查询选择中缺少 3 列,试试这个

SELECT [To_ICJ],
   [From_Reference__c],
   [From Account],
   [Current],
   [30 days],
   [60 days],
   [90 days]
FROM
(Select 
     A.[To_ICJ],
     A.[From_Reference__c],
     A.[From Account],
    Sum(A.[Outstanding]) AS [SumOfOutstanding],
    A.Age AS [PIVOT_ITEM]
FROM dbo.vw_SIMP_EN_F_Tx_AccRec_8 A
GROUP BY A.[To_ICJ],
     A.[From_Reference__c],
     A.[From Account],
     A.Age
) AS p PIVOT(
     Sum([SumOfOutstanding]) FOR [PIVOT_ITEM]
 In ([Current],[30 days],[60 days],[90 days])) as pvt
于 2013-04-14T22:45:25.920 回答