Solved

Pivot not using aggregate yield error

Posted on 2016-11-30
3
13 Views
Last Modified: 2016-12-01
Hello,

What is wrong with this?


BEGIN TRANSACTION
UPDATE tn
  SET tn.[NC_HIST_POST_1] = SubQuery.[2015]
  FROM PS_NC_BUDG_STG_UPL tn  JOIN (
 SELECT *
  FROM (
 SELECT ACCOUNT
 , DEPTID
 , PROGRAM_CODE
 , PROJECT_ID
 , POSTED_TOTAL AS POSTED_TOTAL
 , BUDGET_PERIOD
  FROM PS_NC_BUDG_STG_HIS AS p PIVOT ((p.[POSTED_TOTAL]) FOR [BUDGET_PERIOD]  ([2014]
  , [2015]
  , [2016])) AS pvt
  GROUP BY ACCOUNT
  ,DEPTID
  , PROGRAM_CODE
  , PROJECT_ID
  , [2014]
  , [2015]
  , [2016] ) AS SubQuery ON SubQuery.ACCOUNT = tn.ACCOUNT
   AND SubQuery.PROGRAM_CODE = tn.PROGRAM_CODE
   AND SubQuery.PROJECT_ID = tn.PROJECT_ID
   AND SubQuery.DEPTID = tn.DEPTID
   AND ([2015] IS NOT NULL)


Thanks, Lucia
0
Comment
Question by:Lucia
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
Pawan Kumar Khowal earned 500 total points
Comment Utility
Please try...

BEGIN TRANSACTION 
UPDATE tn 
  SET tn.[NC_HIST_POST_1] = SubQuery.[2015] 
  FROM PS_NC_BUDG_STG_UPL tn  
  JOIN 
  ( 
	  SELECT * 
	  FROM 
	  ( 
			 SELECT 
				ACCOUNT 
				, DEPTID 
				, PROGRAM_CODE 
				, PROJECT_ID 
				, POSTED_TOTAL AS POSTED_TOTAL 
				, BUDGET_PERIOD 
				FROM PS_NC_BUDG_STG_HIS AS p PIVOT ((p.[POSTED_TOTAL]) FOR [BUDGET_PERIOD]  ([2014] , [2015] , [2016])) AS pvt 
				GROUP BY ACCOUNT 
				,DEPTID 
				, PROGRAM_CODE 
				, PROJECT_ID 
				, [2014] 
				, [2015] 
				, [2016] 
		)u
   )AS SubQuery 
       ON SubQuery.ACCOUNT = tn.ACCOUNT 
   AND SubQuery.PROGRAM_CODE = tn.PROGRAM_CODE 
   AND SubQuery.PROJECT_ID = tn.PROJECT_ID 
   AND SubQuery.DEPTID = tn.DEPTID 
   WHERE [2015] IS NOT NULL

Open in new window


Hope it helps !!
0
 

Author Closing Comment

by:Lucia
Comment Utility
Thanks, Lucia
0
 
LVL 17

Expert Comment

by:Pawan Kumar Khowal
Comment Utility
Welcome Lucia !!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now