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

x
?
Solved

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
2
Medium Priority
?
246 Views
Last Modified: 2012-05-11
Select Job, 2003,2004,2005,2006,2007,2008,2009,2010,2011
FROM (
SELECT Job,datepart(year,Acedata.Date) as nYears,
(InCredit+OutDebit) AS SumOfAmount
FROM AceData
)
ps PIVOT(
SUM (SumOfAmount)
FOR nYears IN( [2003],[2004],[2005],[2006],[2007],[2008],[2009],[2010],[2011])
  ) AS pvt

my table is simple,
it has columns
 date,job,incredit,outdebit

I am using mssql 8 express
0
Comment
Question by:goodk
2 Comments
 
LVL 41

Accepted Solution

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

Open in new window

0
 

Author Closing Comment

by:goodk
ID: 35488836
timely and correct!!
0

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