来自临时本地表输出的 UNPIVOT

问题描述 投票:0回答:1

我有以下 SQL,我试图取消临时本地表 #tempTbl_tblF0902 的结果

SELECT 
   [JDE Fiscal Year], [Business Unit], [Cost Code], [Cost Description], [Cost with Description], [Trade Code], [Trade Description], [Trade with Description],
   [Periods], [Postings]
FROM (
   SELECT * FROM #tempTbl_tblF0902
) as pvt

UNPIVOT
(
   [Postings] FOR [Periods] IN ([Balance Forward],[Net Posting 01], [Net Posting 02], [Net Posting 03], [Net Posting 04], [Net Posting 05], [Net Posting 06], [Net Posting 07], [Net Posting 08], [Net Posting 09], [Net Posting 10], [Net Posting 11], [Net Posting 12] )
)

DROP TABLE #tempTbl_tblF0902

但是,我在[期间]、[帖子] 和 DROP 中看到红色波浪线

当我尝试执行脚本时,出现错误提示

无效的列名称“期间”

列名“帖子”无效

我在这里做错了什么,应该如何解决?

提前谢谢您

sql-server unpivot
1个回答
0
投票

发现我的错误。

需要在我的 UNPIVOT 右括号后给出一个别名

UNPIVOT
(
   [Postings] FOR [Periods] IN ([Balance Forward],[Net Posting 01], [Net Posting 02], [Net Posting 03], [Net Posting 04], [Net Posting 05], [Net Posting 06], [Net Posting 07], [Net Posting 08], [Net Posting 09], [Net Posting 10], [Net Posting 11], [Net Posting 12] )
) as unpvt
© www.soinside.com 2019 - 2024. All rights reserved.