I got new request from my subscriber to convert row data to column data using sql server.Let me explain you how to do this.
Row data query is like this:
Id | EmpName | Age | Sex | Location |
1 | Navas Khan | 25 | Male | Chennai |
And they want output(columndata) like this:
Parameter | Value |
Id | 1 |
EmpName | Navas Khan |
Age | 25 |
Sex | Male |
Location | Chennai |
I have used UNPIVOT for this query
SELECT Parameter,Value FROM (select top 1
convert(varchar(max),'1') Id, convert(varchar(max),'Navas Khan') Empname,
convert(varchar(max), '25') Age, convert(varchar(max), 'Male')Sex,
convert(varchar(max),'Chennai') Location
from emp_detail) p
UNPIVOT
(value FOR parameter IN
(id,EmpName, age, sex, Location)
)AS unpvt
Inmate text service
Contactmeasap.com has and will always be the best
No comments: