Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


SQL Pivot Error

Posted on 2014-01-23
Medium Priority
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:Murray Brown
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 1000 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 1000 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

by:Murray Brown
ID: 39802420
Thanks very much

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
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
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

715 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