Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Apportion results to new columns

Author  Topic 

thoron6
Starting Member

7 Posts

Posted - 2014-06-27 : 08:51:20
Morning,

I am quite new to SQL so was wondering if you could help me.

I currently have




Code:
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:


Code Jan data Feb data Mar data


> 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.


Any help would be appreciated.

Thanks

adsingh82
Starting Member

20 Posts

Posted - 2014-06-27 : 11:29:52
please go through the below link, which will get you the clear idea about pivot

[url]http://dotnetbites.com/pivot[/url]

Regards,
Alwyn.M
Go to Top of Page
   

- Advertisement -