Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Pivot not using aggregate yield error

Posted on 2016-11-30
3
Medium Priority
?
104 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
Pawan Kumar earned 2000 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 30

Expert Comment

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

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

715 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