Solved

Pivot not using aggregate yield error

Posted on 2016-11-30
3
61 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 28

Accepted Solution

by:
Pawan Kumar earned 500 total points
ID: 41908321
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
ID: 41908671
Thanks, Lucia
0
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41909649
Welcome Lucia !!
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
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…

830 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