Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a table soctymain it's some rows as.............................


id  | socityname |  house |  population |  areaofsocity
1   |  abcd      |  10    |   150       |     10
2   |  cdf       |  5     |     15      |     20  
3   |  zxc       | 20     |   20        |     10   
4   |  bnm       | 98     |  10         |    30



i want reslut sum of socityid,sum of hpuse,sumof population in range of areawise like this..............


values     |  0to10 |   11to20 |  21to30  |  31up
socity     |   2    |     1    |    1     |
house      |  30    |   5      |   98     |
population |   170  |     15   |    10    |
Posted
Updated 11-Mar-13 23:30pm
v2
Comments
Aarti Meswania 12-Mar-13 5:31am    
why repost ???
http://www.codeproject.com/Answers/560492/unpivotplustablepluspluscolumnplusvalue#answer2

see solution 2 it's working
rahul 92 12-Mar-13 6:12am    
coz peopil give me answer for only static value which i declare in my qustion ...........
not all table value......
i need the answer for all the vlues which is in my table
Aarti Meswania 12-Mar-13 6:15am    
simply go for grouping
you can display data in presentation layer as u want

and if you don't want this then search for "dynamic pivot query in sql"
rahul 92 12-Mar-13 7:02am    
ok thanks..............

Aarti Meswania 12-Mar-13 7:04am    
pivot always need fix column value so for dynamic you have to try dynamic pivot query like...

http://stackoverflow.com/questions/2554826/dynamic-sql-to-generate-column-names

https://www.simple-talk.com/blogs/2007/09/14/pivots-with-dynamic-columns-in-sql-server-2005/

http://stackoverflow.com/questions/7822004/pivots-with-dynamic-columns-in-sql-server

most welcome
Glad to help you! :)

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