HI Everyone,
I am using pivot function of sql. its working fine.
but i want to change the column sequence which pivot created
Following are example :
Table A :
Month | Amount | Gender | Name
jan 20 Male A
Feb 30 Female B
March 40 Male C
For this table i am using following query
SELECT * FROM (
Select Month,Amount,Name From A
)AS S
PIVOT(
SUM(Amount)
FOR Name IN ([A],[B],[C]))AS p
this will give me output
Month |Gender| A |B |C
JAN Male 20 Null Null
Feb Female Null 30 Null
March Male Null Null 40
But I want The sequence of column like
Month,A,B,C then Gender
That mean column generated by pivot should come second and after that remaining column
NOTE : pivot generated Dynamically column that's why i am not aware about the column name
for example i will put a,b,c as column name in this example.
Thanx
Chetan V.