Convert Rowto Column

Sunil Soni
Posted by Sunil Soni under Sql Server category on | Points: 40 | Views : 2407
CREATE TABLE [dbo].[Call](
[call_id] [smallint] NULL,
[Emp_id] [smallint] NULL,
[call_status_id] [smallint] NULL
) ON [PRIMARY]


insert into call (call_id,Emp_id,Call_status_id) values (1,25,101)
insert into call (call_id,Emp_id,Call_status_id) values (2,26,102)
insert into call (call_id,Emp_id,Call_status_id) values (3,26,103)
insert into call (call_id,Emp_id,Call_status_id) values (4,28,104)
insert into call (call_id,Emp_id,Call_status_id) values (5,25,105)

select * from call

SELECT [101] , [102], [103],[104],[105]
FROM ( SELECT [call_status_id], call_id FROM call)
P PIVOT ( sum(call_id) FOR [call_status_id] IN ([101] , [102], [103],[104],[105])) AS pvt

Comments or Responses

Posted by: T.saravanan on: 9/14/2011 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi sunil,

kindly give the output of the query its really useful to viewers and also post your code inside the code tag.

Login to post response