I have a Microsoft SQL Server 2008 R2 table as follows..
If I select where year = 2013 and 2014 it returns 2 rows per crmcref (Account Number)
I need to sum mtdvalue_5, mtdvalue_6, mtdvalue_7, mtdvalue_8, mtdvalue_9, mtdvalue_10, mtdvalue_11, mtdvalue_12 where year is 2013 and then add mtdvalue_1, mtdvalue_2, mtdvalue_3, mtdvalue_4 where year is 2014
In essence the data is split into Financial Years and I need to work out the math based on Past 12 months (mtdvalue_1) being May and year being financial year (2014 being current year).
I would really appreciate some help.
Its worth noting I have no control of the database tables and structure (normalization), but I can create views.
Mim
SQL:
CREATE TABLE [dbo].[CRSpendByPeriod](
[crmcref] [char](6) NOT NULL,
[year] [numeric](5, 0) NOT NULL,
[mtdvalue_1] [numeric](10, 2) NULL,
[mtdvalue_2] [numeric](10, 2) NULL,
[mtdvalue_3] [numeric](10, 2) NULL,
[mtdvalue_4] [numeric](10, 2) NULL,
[mtdvalue_5] [numeric](10, 2) NULL,
[mtdvalue_6] [numeric](10, 2) NULL,
[mtdvalue_7] [numeric](10, 2) NULL,
[mtdvalue_8] [numeric](10, 2) NULL,
[mtdvalue_9] [numeric](10, 2) NULL,
[mtdvalue_10] [numeric](10, 2) NULL,
[mtdvalue_11] [numeric](10, 2) NULL,
[mtdvalue_12] [numeric](10, 2) NULL,
[ytdvalue] [numeric](10, 2) NULL,)
ON [PRIMARY]
GO
If I select where year = 2013 and 2014 it returns 2 rows per crmcref (Account Number)
I need to sum mtdvalue_5, mtdvalue_6, mtdvalue_7, mtdvalue_8, mtdvalue_9, mtdvalue_10, mtdvalue_11, mtdvalue_12 where year is 2013 and then add mtdvalue_1, mtdvalue_2, mtdvalue_3, mtdvalue_4 where year is 2014
In essence the data is split into Financial Years and I need to work out the math based on Past 12 months (mtdvalue_1) being May and year being financial year (2014 being current year).
I would really appreciate some help.
Its worth noting I have no control of the database tables and structure (normalization), but I can create views.
Mim