Q:

SQL row output like column

My table design as follows:
BSales:
PCode SaleDate      SaleValue
1     2015-01-01    50000
2     2015-01-01    50000
3     2015-01-01    50000
4     2015-01-01    50000
5     2015-01-01    50000
1     2015-01-02    50000
2     2015-01-02    50000
3     2015-01-02    50000
4     2015-01-02    50000
5     2015-01-02    50000

select PCode,SaleDate,SUM(SaleValue) as Sales 
from [BSales] 
where SaleDate between '2015-01-01' and '2015-01-05' 
group by PCode,SaleDate

this partialy fulfil my desire output.But i want to the output as follows:
 PCode  '2015-01-01'    '2015-01-02'    '2015-01-03'    '2015-01-04'    '2015-01-05'
 1      5000            50000           0               0               0    
 2      5000            50000           0               0               0    
 3      5000            50000           0               0               0    
 4      5000            50000           0               0               0    
 5      5000            50000           0               0               0 

Is it Possible using sql query?or T-SQL?Or using Store Procedure?Anybody helps is greatly appreciated.

A:

You need to look at the pivot options in T-SQL.
For example (not tested!)
SELECT *
FROM BSales
PIVOT(SUM(SaleValue) 
          FOR SaleDate IN ([2015-01-01], [2015-01-02]
                       , [2015-01-03], [2015-01-04], [2015-01-05])) AS PVTTable

Here's a full tutorial on it.
http://sqlhints.com/2014/03/10/pivot-and-unpivot-in-sql-server/

