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: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 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

by:Murray Brown
ID: 39802420
Thanks very much

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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

634 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