Okay Sean:
Here is table 1 - 'overtime budget 2013'
CREATE TABLE [dbo].[Overtime Budget 2013](
[Org Level] [nvarchar](50) NULL,
[Overtime Code] [nchar](10) NULL,
[January] [money] NULL,
[February] [money] NULL,
[March] [money] NULL,
[April] [money] NULL,
[May] [money] NULL,
[June] [money] NULL,
[July] [money] NULL,
[August] [money] NULL,
[September] [money] NULL,
[October] [money] NULL,
[Novemeber] [money] NULL,
[December] [money] NULL,
[Total] [money] NULL
) ON [PRIMARY]
Here's some sample date for the above table:
INSERT Into [Overtime Budget 2013]
SELECT 'WSIDOE','5204 ','1579588.23','1578296.23','1964371.53'
SELECT 'WSIOTH','5204 ','10979.65','11212.00','15404.53'
SELECT 'WSIWMA','5204 ','121070.56','121070.05','149569.32'
SELECT 'WSIUNY','5204 ','1287.29','1287.68','1609.60'
SELECT 'WSIZHR','5204 ','553.85','553.85','692.31'
SELECT 'WSIZSS','5204 ','96.15','96.15','120.19'
The second table is actually a query that looks like this:
/* Summary Overtime by Employee */
SELECT
cast(left(pehPErcontrol,8) as datetime) AS [Period Control Date],
--ltrim(cmpCompanyName) AS [Company Name],
rtrim(eepNameLast) +
--isnull(' '+rtrim(CodDesc), '') +
', ' + rtrim(eepNameFirst) +
' ' + coalesce(substring(eepNameMiddle,1,1) + '.', '') as Name,
eepNameLast AS [Last Name],
IsNull(eepNameSuffix,'') AS [Suffix],
eepNameFirst AS [First Name],
IsNull(eepNameMiddle,'') AS [Middle Name],
--eepSSN,
--pehBatchID AS [Batch ID],
pehCurAmt AS [Current Amount],
pehCurHrs AS [Current Hours],
pehCoID AS [Company ID],
pehEEID AS [EE ID],
pehEmpNo AS [Emp No],
pehLocation AS [Location],
pehJobCode AS [Job Code],
pehOrgLvl1 AS [Org Level 1],
pehOrgLvl2 AS [Org Level 2],
pehOrgLvl3 AS [Org Level 3],
pehOrgLvl4 AS [Org Level 4],
pehPayGroup AS [Pay Group],
pehProject AS [Project],
pehShfShiftAmt AS [Shift Amount],
pehearncode AS [Earn Code],
--new
[overtime code] as [Overtime Code],
[Org Level] as [Org Level],
[January] as [January]
FROM EmpPers JOIN pearhist
ON pehEEID = eepEEID
join GSHQSHAREPOINT.EXECUTIVEDASHBOARD.DBO.[OVERTIME BUDGET 2013] ON [org level] = pehOrgLvl2
where pehearncode = '0002'
AND pehPerControl > '201301011'
--AND pehPerControl > '201301011'
--AND pehOrgLvl2 like '%SRS'
AND pehOrgLvl2 like '%ZSW'
You can see where I'm joining by org level but need to add the months/date to complete.