Solved

SQL Pivot Error

Posted on 2014-01-23
3
357 Views
Last Modified: 2014-01-23
Hi

I am trying a basic SQL pivot example but am getting the error in the following statement:
Incorrect syntax near ')'.


Select * From [Pivot1] as S Pivot (Sum(Amount) For [Month]) As P
0
Comment
Question by:murbro
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
Comment Utility
you are missing the IN() part  ,  after [Month] part, and also not use *  for the select ...

see examples on the technet page here:
http://technet.microsoft.com/library/ms177410%28v=sql.105%29.aspx
0
 
LVL 12

Assisted Solution

by:Saurabh Bhadauria
Saurabh Bhadauria earned 250 total points
Comment Utility
Follow below example to under stand Pivot functionality

DECLARE @pivot TABLE (
	amount INT
	,month CHAR(5)
	)

INSERT INTO @pivot (
	amount
	,month
	)
VALUES (2	,'JAN'	)	,
       (3	,'JAN'	) ,
       (4	,'DEC'	)

SELECT *
FROM @pivot AS S
Pivot(Sum(Amount) FOR [Month] IN (
			[JAN]
			,[DEC]
			)) AS PEND

Open in new window


Thanks,
Saurabh
0
 

Author Closing Comment

by:murbro
Comment Utility
Thanks very much
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

762 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

9 Experts available now in Live!

Get 1:1 Help Now