Q:

How can I split values returned by sql query into multiple columns in SQL SERVER?

I have a function that returns the following information when called:
select * from functionName(null, '1 jan 2016', '30 dec 2016') 

output: 
    pcode       PayoutDate

   100         2016-02-28 00:00:00:000
   100         2016-05-31 00:00:00:000
   100         3016-08-31 00:00:00:000
   100         3016-11-30 00:00:00:000
   103         2016-02-28 00:00:00:000
   103         2016-05-31 00:00:00:000
   103         3016-08-31 00:00:00:000
   103         3016-11-30 00:00:00:000

We do payouts to our clients at the end of February, May, August and November. 
So what I want to achieve is to have each month have its own date as shown below:
pcode    May                        August                November

100    2016-05-31 00:00:00:000  3016-08-31 00:00:00:000  3016-11-30 00:00:00:000 
103    2016-05-31 00:00:00:000  3016-08-31 00:00:00:000  3016-11-30 00:00:00:000 

How can I split the data set to reflect as shown above?
I don't really know how can this be tackled, Anyone with any idea?

A:

Use PIVOT
SELECT * FROM 
(SELECT pcode, datename(month, PayoutDate) AS Month, PayoutDate FROM yourtable) a
PIVOT
(MIN(PayoutDate) FOR Month IN ([May], [August], [November]))b

Output
pcode May                  August               November
100   2016-05-31T00:00:00Z 3016-08-31T00:00:00Z 3016-11-30T00:00:00Z
103   2016-05-31T00:00:00Z 3016-08-31T00:00:00Z 3016-11-30T00:00:00Z

SQL Fiddle: http://sqlfiddle.com/#!6/9ed49/11/0

