Given Below is a Table let us suppose emp.

ID Year Grade
1 2000 1
2 2000 2
3 2000 3
1 2001 2
2 2001 3
3 2001 1
1 2002 3
2 2002 1
3 2002 2
NULL NULL NULL

I want to write a query which gives me the output as

ID Grade(2000) Grade(2001) Grade(2002)

1 1 2 3
2 2 3 1
3 3 1 2


also kindly try to provide me a generic solution so that if the number of years increases for an id it gives that number of columns.

Thanks
Praveen