Morning,
I am quite new to SQL Server 2008 so I was wondering if you could help me.
I currently have:
SELECT
c.code, d.date, d.date_previous,
CAST(d.date-date_previous as int) AS Days,
d.units, d.cost
FROM table1 AS d
INNER JOIN table2 AS p ON d.ID = p.ID
INNER JOIN table3 AS c ON p.c_id = c.ID
WHERE date_previous > '31/12/2012'
This is bringing back one row per invoice received after 31/12/2012. The aim is to get the following columns:
Code Jan data Feb data Mar data etc...
- one unique code per line (so I'm assuming row partitioning is required)
- Where a bill has a period of 3 months with, for example, 300 units, I'd like that separated out across 3 months (100 in each)
I'm aware I'd probably need to use a pivot function and some temp tables but I'm not that advanced yet.