Manish Patat

Manish Patat

  • 1.7k
  • 68
  • 7.7k

SQl Query Pivot table

Oct 13 2020 1:45 AM
This is my Query :-
  1. SELECT  
  2. isnull(cast(year as varchar(25)),0) AS Year,  
  3. isnull(cast(January as varchar(25)),0) AS January,  
  4. isnull(cast(February as varchar(25)),0) AS February,  
  5. isnull(cast(March as varchar(25)),0) AS March,  
  6. isnull(cast(April as varchar(25)),0) AS April,  
  7. isnull(cast(May as varchar(25)),0) AS May,  
  8. isnull(cast(June as varchar(25)),0) AS June,  
  9. isnull(cast(July as varchar(25)),0) AS July,  
  10. isnull(cast(August as varchar(25)),0) AS August,  
  11. isnull(cast(September as varchar(25)),0) AS September,  
  12. isnull(cast(October as varchar(25)),0) AS October,  
  13. isnull(cast(November as varchar(25)),0) AS November,  
  14. isnull(cast(December as varchar(25)),0) AS December,  
  15. isnull(January,0)+ISNULL(February,0)+ISNULL(March,0)+ISNULL(April,0)+ISNULL(May,0)+ISNULL(June,0)+ISNULL(July,0)+ISNULL(August,0)+ISNULL(September,0)+ISNULL(October,0)+ISNULL(November,0)+ISNULL(December,0) As 'Total Weight'  
  16. FROM orderbookingdispatchmwise  
  17. PIVOT (SUM(weight) FOR month IN ([January], [February], [March], [April], [May], [June], [July], [August], [September], [October], [November], [December])) AS PVTTable  
  18. ORDER BY year DESC   
My Output
 
 
On this Query Output All Year And Month Data Show 
 
But I Have Show Only Current Month And year Greater Than Data
 
my required Output Like..
 
 
How to Possible 
Thank in advance ... 

Answers (3)