I want to build dynamic sql query based on following
SELECT P.Trackingno,PA.SKUId,SC.SKUName,count(PA.SKUId) as TotalSKUId
,sum(case when PA.IsAvailable = 1 then 1 else 0 end) AS IsAvailable
FROM ADMIN.posavailability PA
LEFT OUTER JOIN Admin.SKUCreation SC ON SC.TCID=PA.Skuid
LEFT OUTER JOIN Admin.POSVisitDetails PD on PD.VisitId=PA.VisitID
LEFT OUTER JOIN Admin.POS P ON P.TrackingNo=PD.TrackingNo
WHERE PA.VisitId in
(SELECT visitid FROM Admin.POSVisitDetails PD WHERE PD.month=2 and PD.year=2017)
and PA.IsActive=1
GROUP BY P.Trackingno,PA.SKUId,SC.SKUName,PD.Month,PD.year
ORDER BY P.Trackingno
I got out as follows:
My desired output is:
Can any one help for dynamic pivot SQL query.

