una tabla pivote multiple filas fechas ejemplo dinamico concatenar con columns columna 10g sql sql-server-2008-r2 syntax-error pivot subtotal

sql - tabla - pivot oracle columns to rows



Error de sintaxis subtotal de la tabla pivote SQL (1)

Espero que alguien pueda ayudarme. Pude armar este script SQL, pero vuelve con errores menores aquí y allá. He intentado depurar durante más de una semana. Por favor ayuda. el primer mensaje de error es "Sintaxis incorrecta cerca de '')''." Si corrige que sigue tirando más, creo que no estoy codificando esto correctamente. No puedo guardar los cambios que sí funcionan. me dice que se canceló la solicitud de guardado. Trabajando con SQL Server 2008 r2

SELECT PublicationID AS PubID, (PubNum + ''- '' + PubTitle) AS [Pub Descr], CONVERT(Varchar(10), [Datestamp], 101) AS [Date Printed], QtyPrinted AS [Qty Printed], [2] AS [Tyler Inventory], [1] AS [Central Inventory], [3] AS [Mailing House Inventory], ( SELECT SUM(S) FROM ( SELECT [1] UNION ALL SELECT [2] UNION ALL SELECT [3] ) AS T (S)) AS [Current Inventory], RecycledQty AS [Recycled], MailingVendorName AS [Mailing Vendor], PrintVendorName AS [Print Vendor] FROM ( SELECT PublicationID, LocationID, Balance, PubNum, PubTitle, ItemPerCase, Datestamp, Deleted, RecycledQty, MailingVendorName, PrintVendorName, QtyPrinted FROM ( dbo.view_PubInventory_Main_Summary_RAW) x PIVOT (sum(balance) FOR LocationID IN ([1], [2], [3])) p) SELECT * FROM (SELECT PUBID, [Pub Descr], [Date Printed], [Qty Printed], [Tyler Inventory], [Central Inventory], [Mailing House Inventory], [Current Inventory], [Recycled], [Mailing Vendor] FROM GG ) AS T


Es difícil seguir exactamente lo que busca, pero creo que quiere que Current Inventory sea [1]+[2]+[3] y no alias su subconsulta. La consulta en la parte inferior se ve bien.

SELECT PublicationID AS PubID , PubNum + ''- '' + PubTitle AS [Pub Descr] , CONVERT(VARCHAR(10), [Datestamp], 101) AS [Date Printed] , QtyPrinted AS [Qty Printed] , [2] AS [Tyler Inventory] , [1] AS [Central Inventory] , [3] AS [Mailing House Inventory] , [1]+[2]+[3] AS [Current Inventory] , RecycledQty AS [Recycled] , MailingVendorName AS [Mailing Vendor] , PrintVendorName AS [Print Vendor] FROM ( SELECT PublicationID , LocationID , Balance , PubNum , PubTitle , ItemPerCase , Datestamp , Deleted , RecycledQty , MailingVendorName , PrintVendorName , QtyPrinted FROM dbo.view_PubInventory_Main_Summary_RAW PIVOT ( SUM(balance) FOR LocationID IN ( [1], [2], [3] ) ) p )AS Sub