SQL Pivot Error

Posted on 2014-01-23
Last Modified: 2014-01-23

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
Question by:murbro
LVL 143

Accepted Solution

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

see examples on the technet page here:
LVL 12

Assisted Solution

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

	amount INT
	,month CHAR(5)

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

FROM @pivot AS S
Pivot(Sum(Amount) FOR [Month] IN (
			)) AS PEND

Open in new window


Author Closing Comment

ID: 39802420
Thanks very much

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TSQL convert date to string 4 34
Problems "swapping" SQL Server DBs 2 19
sql server query 18 39
Parse this column 6 27
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

860 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