December 28, 2010 at 8:36 am
Hi all,
A quick question and silly one. Does Pivot in tsql work in ssms 2008 r2 ?
i'm trying to use it but its throwing a syntax error. Below is the sample table and code that i borrowed from a website. I havent used pivot before.
USE [Test]
GO
CREATE TABLE [dbo].[SoftwareDemo](
[SoftwareName] [nvarchar](50) NOT NULL,
[Count] [int] NOT NULL,
[Country] [nvarchar](50) NOT NULL
) ON [PRIMARY]
--insert the sample data:
INSERT INTO SoftwareDemo VALUES ('Project', 15, 'Canada')
INSERT INTO SoftwareDemo VALUES ('Visio', 12, 'Canada')
INSERT INTO SoftwareDemo VALUES ('Project', 10, 'USA')
INSERT INTO SoftwareDemo VALUES ('Visio', 5, 'USA')
--Here’s our PIVOT query:
SELECT Softwarename, Canada, USA, Canada + USA AS TOTAL FROM SoftwareDemo
PIVOT
(
SUM([Count])
FOR Country
IN (Canada, USA)
) AS x
--The error im gettin is:
Msg 170, Level 15, State 1, Line 4
Line 4: Incorrect syntax near '('.
December 28, 2010 at 10:42 am
Never mind....i got it.....i was on 2000 server...thanks all
December 28, 2010 at 9:25 pm
kevin4u06 (12/28/2010)
Never mind....i got it.....i was on 2000 server...thanks all
Heh... scary stuff that we've all done. Glad it wasn't something like dropping a table from a dev server... or was that the production server? 😛
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply