This is initially intended to be a pivot display rather than manipulating data. However, I needed to show all days covered into selected month which the data doesn't have. Not all days we have payment. So for example, I have the month of May 2017, and we were only paid 6 times. I needed to show other days with 0 values as there was no payment supplied.
So what I wanted is to put the payment into the corresponding column/day. Below is my sample data for April.
Below is my current code..
INSERT INTO @tPivot
(
--f_ID,
f_Name,
[1], [2], [3], [4], [5], [6], [7], [8], [9], [10],
[11], [12], [13], [14], [15], [16], [17], [18], [19], [20],
[21], [22], [23], [24], [25], [26], [27], [28], [29], [30],
[31]
)
SELECT c.f_completeName as 'Name',
p.f_payment as 'Payment',
DAY(p.f_date) as 'Date'
FROM tCustomer c
I don't really know how this is called, so I cannot properly search the web. Hoping for some help.. My expected outcome would be..
Name | 1 | 2 ... | 11 | ... | 19
Man-- | .............. | 1000
Agu-- | ............................| 5000