Wrox Programmer Forums
|
SQL Server 2008 General discussion of SQL Server *2008* version only - not related to a specific book.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2008 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 20th, 2012, 09:52 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 112
Thanks: 12
Thanked 0 Times in 0 Posts
Default PIVOT question...

Hi to all... i have this select statement using PIVOT and its working great...

i would like to add a SUM column which would sum up [4],[5],[6], columns...

select statement output below

Select INUMBR,Class,IDSCCD,Descr,OO,ISNULL([4],0) AS [4], ISNULL([5],0) AS[5] , ISNULL([6],0) AS [6], ISNULL(,0) AS
From (
select convert(varchar,x.INUMBR) as 'INUMBR',x.ICLAS Class,IDSCCD, Replace(x.IDESCR, '"', '') as Descr,
y.IBPOOQ as OO,y.ISTORE as 'Store', y.IBHAND as 'OH'
FROM AS4001.HARTMMS.MM750LIB.INVMST x, AS4001.HARTMMS.MM750LIB.INVBAL y
where
x.INUMBR = y.INUMBR group by x.INUMBR,x.ICLAS,IDSCCD, x.IDESCR,y.IBPOOQ, y.ISTORE, y.IBHAND
) as SourceTable
PIVOT (
MAX(OH)
FOR Store in ([4], [5], [6], )) AS Store
order by 1, 2

like to add SUM(4-8)

numbr class Desc OO SUM(4-8) 4 5 6 8
102717 704 D MAGIC .00 .00 .00 .00 .00
102718 704 D DRAW .00 .00 .00 .00 .00
102723 704 D 4 PCE .00 .00 .00 .00 .00
102725 702 D PRETT .00 .00 2.00 .00 .00
103700 517 D (UPC) .00 .00 .00 .00 3.00
103704 517 D ROYA .00 .00 .00 .00 .00


thanking you in advance

Rino





Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter Pivot Table(s) based on Cell Value outside Pivot steplawn Beginning VB 6 0 May 11th, 2010 09:01 PM
Pivot? bph SQL Language 2 September 1st, 2009 01:21 PM
Cumulative % in Pivot Umasriram2 Excel VBA 0 August 7th, 2008 08:30 AM
Pivot Tables smartgir Excel VBA 0 May 12th, 2004 10:08 AM
Pivot Forms!! timmaher Access VBA 0 July 11th, 2003 03:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.