Introduction The PIVOT() function in MS SQL Server is very useful function. This is works like Cross-Tab table in Crystal Report. Explanation For an instance, as shown below table, we have customer,Yr,Mothname, and TTL columns. The Year column consisting distinct records 2009,2010 year. If you want to show the Year data as each column header name, then you will have to use the PIVOT() function to show the distinct records as column header. SELECT user_id Customer,datepart(“yyyy”,order_date) Yr,datename(month,order_date) [Month] , isnull(sum(total_value),0) TTL FROM tbl_po_master group by user_id,datepart(“yyyy”,order_date),datename(month,order_date) Using PIVOT() function In PIVOT() function, you must specify the column values as shown below, select * from (SELECT user_id Customer,datepart(“yyyy”,order_date) Yr,datename(month,order_date) [Month] , isnull(sum(total_value),0) TTL FROM tbl_po_master group by user_id,datepart(“yyyy”,order_date),datename(month,order_date) ) s PIVOT ( sum(...