1
Answer

pivot in sql server

jyoti sagar

jyoti sagar

8y
290
1
I have a salary table like:-<div><table border="0" cellspacing="2" cellpadding="2" width="500"><tbody><tr><td colspan="1">&nbsp;EmpCode&nbsp;&nbsp;&nbsp;</td><td rowspan="1">&nbsp;month</td><td rowspan="1">&nbsp;salary</td></tr><tr><td>&nbsp;1&nbsp;&nbsp;&nbsp;</td><td>&nbsp;Feb2015</td><td>&nbsp;32000</td></tr><tr><td>&nbsp;1</td><td>&nbsp;march2015</td><td>&nbsp;32000</td></tr></tbody><tbody><tr><td>&nbsp;2</td><td>&nbsp;Feb2015&nbsp;&nbsp;&nbsp;</td><td>&nbsp;41000</td></tr></tbody><tbody><tr><td>&nbsp;3</td><td>&nbsp;feb2015</td><td>&nbsp;30000</td></tr></tbody><tbody><tr><td>&nbsp;3</td><td>&nbsp;march2015</td><td>&nbsp;30000</td></tr></tbody><tbody><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></tbody></table></div><div>&nbsp;</div><div>i want result set like:-</div><div><table border="0" cellspacing="2" cellpadding="2" width="500" tagtype="InsertTable"><tbody><tr><td>&nbsp;EmpCode</td><td>&nbsp;Jan2015</td><td>&nbsp;Feb2015</td><td>&nbsp;March2015</td></tr><tr><td>&nbsp;1</td><td>&nbsp;null&nbsp;&nbsp;&nbsp;</td><td>&nbsp;32000</td><td>&nbsp;march2015</td></tr><tr><td>&nbsp;2</td><td>&nbsp;null</td><td>&nbsp;41000</td><td>&nbsp;null</td></tr></tbody><tbody><tr><td>&nbsp;3</td><td>&nbsp;null</td><td>&nbsp;30000</td><td>&nbsp;30000</td></tr></tbody></table></div><div>&nbsp;</div><div>&nbsp;</div><div>&nbsp;</div>
Answers (1)