I need to know whether 'pivot' in SQL Server can be used for converting rows to columns if there is no aggregate function to be used. I saw lot of examples with aggregate function only. My columns are string data type and I need to convert this row data to column data. This is why I wrote this question. I just did it with case
. Can anyone help me......Thanks in advance.
Sample format
empid wagecode amount
1 basic 1000
1 TA 500
1 DA 500
2 Basic 1500
2 TA 750
2 DA 750
Desired output:
empid basic TA DA
1 1000 500 500
2 1500 750 750
MIN()
when you're pivoting without really aggregating. As long as there's just one value,MIN()
orMAX()
will work just as well. Also, it works for string values as described by your title (though contradicted by the body of your question!).