Click here to Skip to main content
15,892,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
select Planttype ,sum(noof50kgsbags*50)[50 Kg],sum(noof70kgsbags*70)[70 Kg] from K_FeedPlantEntryIndent WHERE     (date BETWEEN '2013-04-01 00:00.000' AND getdate()) AND (attrited = 'True')
group by planttype


OUTPUT:
SQL
Planttype  50 Kg	70 Kg
Rohini	   56150	220990
Sneha	   43950	0
KJL	  353550	2426130
Suguna  1290850	        0


Using Pivot:
SQL
select '50KG' [Bags],*from 
(select planttype ,sum(noof50kgsbags*50)[50 Kg] from K_FeedPlantEntryIndent WHERE  (date BETWEEN '2013-04-01 00:00.000' AND getdate()) AND (attrited = 'True')
group by planttype)as t
PIVOT
( sum([50 Kg])
 for[planttype] in(Rohini,Sneha,KJL,Suguna)
  )
 As t2



Pivot Output:
SQL
Bags	Rohini	Sneha	KJL	Suguna
50KG	56150	43950	353550	1290850


Desired Output
SQL
Bags	Rohini	Sneha	KJL	Suguna
50KG	56150	43950	353550	1290850
70KG      x       x       x       x
Posted
Updated 6-Aug-13 1:50am
v3
Comments
Maciej Los 6-Aug-13 8:06am    
Do not repost! You've got your answer here: How to exchange rows and columns heads in sqlserver -2005[^]

1 solution

Write three queries, one for 50Kg, one for 70kg and then union it.
 
Share this answer
 
Comments
Bhagavan Raju M 6-Aug-13 8:01am    
@Syed Asif Iqal . ThankU . I ts workin with simple solution .
Maciej Los 6-Aug-13 8:05am    
No! This is bad idea! All what you need is pivot table!
See my comment to the question.
_Asif_ 6-Aug-13 9:32am    
Indeed the design is bad but given the extremely limited information and the skillset, this could be the immediate working solution.
Maciej Los 6-Aug-13 15:49pm    
Design is not so bad, but implementation is very bad.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900