[Last Call] Learn how to a build a cloud-first strategyRegister Now


I see years - I wanted to see the sum of  SumOfAmount in rows and columns and years as column headings - what am I doing wrong?

Posted on 2011-04-28
Medium Priority
Last Modified: 2012-05-11
Select Job, 2003,2004,2005,2006,2007,2008,2009,2010,2011
SELECT Job,datepart(year,Acedata.Date) as nYears,
(InCredit+OutDebit) AS SumOfAmount
FROM AceData
SUM (SumOfAmount)
FOR nYears IN( [2003],[2004],[2005],[2006],[2007],[2008],[2009],[2010],[2011])
  ) AS pvt

my table is simple,
it has columns

I am using mssql 8 express
Question by:goodk
LVL 41

Accepted Solution

ralmada earned 2000 total points
ID: 35485490
you're missing brackets there
Select 	Job, 
	SELECT Job,datepart(year,Acedata.Date) as nYears, 
	(InCredit+OutDebit) AS SumOfAmount 
	FROM AceData 
) ps 
SUM (SumOfAmount) 
FOR nYears IN([2003],[2004],[2005],[2006],[2007],[2008],[2009],[2010],[2011])
  ) AS pvt

Open in new window


Author Closing Comment

ID: 35488836
timely and correct!!

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

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