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

x
?
Solved

SQL Pivot Error

Posted on 2014-01-23
3
Medium Priority
?
371 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 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:
http://technet.microsoft.com/library/ms177410%28v=sql.105%29.aspx
0
 
LVL 12

Assisted Solution

by:Saurabh Bhadauria
Saurabh Bhadauria earned 1000 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

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