when i issue select statement like
SELECT EMPID,ENAME,SALARY,DEPARTMENT from EMPLOYEE
then data shows like
EMPID ENAME SALARY DEPARTMENT
---------------------------------------------
01 TEST1 2000 A/C
02 TEST2 3000 SALES
but now i want to show it like
EMPID 01 02
ENAME TEST1 TEST2
SALARY 2000 3000
DEPARTMENT A/C SALES
so how to write sql for the above query.
Maybe something like this:
First some test data:
The get the columns to
PIVOTon. I use theROW_NUMBERover theEMPID:Then do a dynamic pivot like this. The
orderWeightso that you will have the order of the columns:Then in my case I will drop the temp table