Reputation: 1
I have an SQL query here, which works perfectly fine:
select
R.[Source_Loaction] as VendorID
,R.[Article_Nbr]
,A.[Article_Desc]
,S.[Destination_Location] as Site
,AH.[External_Product_SType_Arth_Desc] as Product_Subtype
,datepart (week, R.[Scheduled_Ship_dae]) as WK
,SUM(S.[Major_Ship_Qty]) as UoM
,SUM(R.[Shipment_Qty]) as Qty
from [dbo].[FnR_RECEIVED_SHIPMENT_V] as R
INNER JOIN [dbo].[FnR_SOURCING_V] as S
ON (R.[Article_Nbr]=S.[Article_Nbr] AND R.[Destination_Location]=S.[Destination_Location])
INNER JOIN [dbo].[FnR_EXTERNAL_ARTICLE_V] as AH
ON R.[Article_Nbr]=AH.[Article_Nbr]
INNER JOIN [dbo].[FnR_ARTICLE_V] as A
ON R.[Article_Nbr]=A.[Article_Nbr]
Group by
R.[Source_Loaction]
,R.[Article_Nbr]
,A.[Article_Desc]
,S.[Destination_Location]
,AH.[External_Product_SType_Arth_Desc]
,datepart (week, R.[Scheduled_Ship_dae])
I wish to place a PIVOT table as structured HERE:
PIVOT(sum(Qty) for [WK] in ([25],[26],[27],[28],[29],[30],[31],[32],[33],[34],[35],[36])) as pivot
These two SQL functions are not working together and I am unsure where to place the pivot. Could someone assist as to where I have gone wrong on this one? The items 25 through 36 in the pivot tables are week start dates and this is what I wish to pivot on.
I appreciate any incite.
I am creating a pivot table on qty's based on week function. Once I can do this, I have my problem solved.
Upvotes: 0
Views: 102
Reputation: 51494
select *
from
(
-- your first query here
) src
PIVOT(sum(Qty) for [WK] in ([25],[26],[27],[28],[29],[30],[31],[32],[33],[34],[35],[36])) as pivot
as per the documentation
Upvotes: 1