Solved

SQL Pivot Error

Posted on 2014-01-23
3
365 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 143

Accepted Solution

by:
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:
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
ID: 39802399
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
ID: 39802420
Thanks very much
0

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