Solved

SQL Pivot Error

Posted on 2014-01-23
3
368 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:Murray Brown
[X]
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
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:Murray Brown
ID: 39802420
Thanks very much
0

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