December 10, 2010 at 8:46 pm
I currently have a table in this format:
DOCDATE | Ship | Vendor | PassengerCount | TrxFullPrice | TrxQuantity
In the Vendor Column I have a few vendors such as HOF & JHC
I have pivoted the table using this code.
SELECT *
FROM ( SELECT ship ,
passengercount ,
trxfullprice ,
docdate ,
vendor
FROM dbo.ICL_Sockeye_Flashreport
WHERE mediacompany = 'ppi'
AND docdate BETWEEN 'november 1 2010'
AND 'november 30 2010'
) f PIVOT ( SUM(TrxFullPrice) FOR Vendor IN ( hof, jhc ) ) p
ORDER BY ship
with this result:
ship | passengercount | docdate | hof | jhc
I have omitted the Column TrxQuantity because I need to SUM it as well in the pivot.
I am trying to get this result:
ship | passengercount | docdate | hof | TrxQuantity | Trx jhc | TrxQuantity
Any help would be appreciated as this is too complex for me to do & researching is making it worse.
December 11, 2010 at 9:30 am
You need to look at the two articles in my signature that deal with Cross-tabs/Pivot Tables (parts 1 and 2) - I think that these will get you what you need.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
December 11, 2010 at 1:49 pm
Also, if you post data as outlined in the article at the first link in my signature line below, you might even get someone to provide a tested, coded answer. 😉
--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