-5

My table structure is as below:

Person_id      Add_Type        Address
1              Present         A
1              Permanent       B

I want pivot table as below:

Person_id      Present       Permanent
1                A             B
Arulkumar
  • 12,966
  • 14
  • 47
  • 68
  • You could look into the PIVOT command – Rich Benner Apr 29 '16 at 07:29
  • Possible duplicate of [Convert Rows to columns using 'Pivot' in SQL Server](http://stackoverflow.com/questions/15931607/convert-rows-to-columns-using-pivot-in-sql-server) – Shnugo Apr 29 '16 at 07:39

1 Answers1

1

First at all try to use any search engine... This is what you need:

SAMPLE DATA

create table #t
(
   Person_id VARCHAR(MAX),
   Add_Type VARCHAR(MAX),
   Address_ VARCHAR(MAX)
)
insert into #t values ('1','Present', 'A'), ('1','Permanent', 'B')

QUERY

select *
from (select Person_id, Add_Type, Address_ 
      from #t 
      )as src
pivot
(
   min(Address_)
   for Add_Type in ([Present], [Permanent])
) as pvt

OUTPUT

Person_id      Present       Permanent
1              A             B