• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 466
  • Last Modified:

PIVOT Syntax HELP....!

Experts:

Can someone eyeball this SQL which uses PIVOT and help me with the error? It works find until I try to ADD more that ONE field to the SUM in the PIVOT..???

--Weekly Reserve Data
select distinct Portfolio_wk
 , count( [Orderid]) as OrderCount
 , sum(case when [Customer?] = 'Customer' then 1 else 0 end) as CustomerCount
 , [1] as [2008-10-20]
 , [2] as [2008-10-27]
 , [3] as [2008-11-03]
 , [4] as [2008-11-10]
 , [5] as [2008-11-17]
 , [6] as [2008-11-24]  -- <== Add weeks here to increase the columns
from
  (select portfolio_wk,orderid, customerid, isnull(cogsamount,0) as cogsamount, [customer?], cogswp, cogsrca from dbo.reserve) r
PIVOT
(sum(cogsamount) for cogsamount  in ([1],[2],[3],[4],[5],[6]))  -- <--THIS WORKS
(sum(cogsamount + cogswp + cogsrca) for cogsamount  in ([1],[2],[3],[4],[5],[6])) -- <--THIS DOES NOT
as pvt
group by portfolio_wk, pvt.[1], pvt.[2], pvt.[3], pvt.[4], pvt.[5], pvt.[6]

Basically I need to have a SUM of the 3 columns cogsamount, cogswp, cogsrca

AWARDING POINTS FAST....

thanks
M
0
MIKE
Asked:
MIKE
  • 2
1 Solution
 
MIKESoftware Solutions ConsultantAuthor Commented:
ooops...sorry here is the error:

Msg 102, Level 15, State 1, Line 15
Incorrect syntax near '+'.
0
 
MIKESoftware Solutions ConsultantAuthor Commented:
I forgot to comment out ONE of those lines referenced..but hopefully you'll understand what i mean....

How do I combine 3 columns of data and SUM them for the PIVOT...???
0
 
SharathData EngineerCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now