Hi
I have one table like
Columsns
ID(Primary key) AP MP TN MP ..... These are all state names as columns
my query returning the data like
Statename Count
AP 10
MP 20
TN 30
How can i insert this result set in to table in sql server.
Please help
Regards
Ajay
Loading
Jignesh TrivediPosted Mar 12, 2012, 12:01 AM
you can solved your problem using PIVOT Query in SQL
For this you must have fix column means AP,MP, ect are fixed.
Now I am assume your table just like table created by Senthilkumar( in above post).
try....
SELECT *
FROM
(SELECT StateName, COUNT(*) AS [Count1] FROM States GROUP BY StateName ) ps
PIVOT
(
sum (Count1)
FOR StateName IN
( [AP], [MP],[TN])
) AS pvt
please refer
http://blog.sqlauthority.com/2008/06/07/sql-server-pivot-and-unpivot-table-examples/
hope this help.
SenthilkumarPosted Mar 9, 2012, 2:11 AM
If it is helps you then please mark as accepted answer.