I need to create a stored procedure that adds a new column every month. I have never done anything like this before so I am hoping someone could help me. My current stored procedure looks like this:
CREATE PROCEDURE dbo.TIME_IPLC_MAPct
@BeginPeriod int,
@EndPeriod int
AS
SELECT tk.tkinit
, tk.tklast + ', ' + tk.tkfirst TKName
, tk.tktitle
, p.period
, ISNULL(SUM(CASE WHEN m.mnonbill is null AND
(m.mmatter like '%-002%' OR m.mmatter like '%-
006%') THEN tworkhrs ELSE 0 END)
/NULLIF(SUM(CASE WHEN mnonbill is null THEN
tworkhrs ELSE 0 END), 0),0) PctMAHours
FROM timecard t
INNER JOIN matter m ON t.tmatter = m.mmatter
INNER JOIN timekeep tk ON t.ttk = tk.tkinit
INNER JOIN eis_period p ON t.twoper = p.per
WHERE p.period between @BeginPeriod and @EndPeriod
AND (tk.tksect = 'IPLC' OR tkinit = '1106')
AND t.tstatus <> 'E'
AND tktmdate is null
GROUP BY tk.tkinit, tk.tklast + ', ' + tk.tkfirst, tk.tktitle, p.period
ORDER BY tk.tktitle, TKName
I used to run this and dump to Excel and pivot table in order to get the data grouped by month. The excel output columns look like this:
Percentage of M&A Hours
Nov-07 Dec-07 Jan-08 Feb-08 Mar-08
My boss wants this report automated so that for April say, the end user will put a beginning period of 200711 (for Nov 2007) and an ending period of 200804 (for April 2008). The report would then show:
Percentage of M&A Hours
Nov-07 Dec-07 Jan-08 Feb-08 Mar-08 Apr-08
This will continue every month until we hit 12 months.
Any help/advice would be appreciated.
CREATE PROCEDURE dbo.TIME_IPLC_MAPct
@BeginPeriod int,
@EndPeriod int
AS
SELECT tk.tkinit
, tk.tklast + ', ' + tk.tkfirst TKName
, tk.tktitle
, p.period
, ISNULL(SUM(CASE WHEN m.mnonbill is null AND
(m.mmatter like '%-002%' OR m.mmatter like '%-
006%') THEN tworkhrs ELSE 0 END)
/NULLIF(SUM(CASE WHEN mnonbill is null THEN
tworkhrs ELSE 0 END), 0),0) PctMAHours
FROM timecard t
INNER JOIN matter m ON t.tmatter = m.mmatter
INNER JOIN timekeep tk ON t.ttk = tk.tkinit
INNER JOIN eis_period p ON t.twoper = p.per
WHERE p.period between @BeginPeriod and @EndPeriod
AND (tk.tksect = 'IPLC' OR tkinit = '1106')
AND t.tstatus <> 'E'
AND tktmdate is null
GROUP BY tk.tkinit, tk.tklast + ', ' + tk.tkfirst, tk.tktitle, p.period
ORDER BY tk.tktitle, TKName
I used to run this and dump to Excel and pivot table in order to get the data grouped by month. The excel output columns look like this:
Percentage of M&A Hours
Nov-07 Dec-07 Jan-08 Feb-08 Mar-08
My boss wants this report automated so that for April say, the end user will put a beginning period of 200711 (for Nov 2007) and an ending period of 200804 (for April 2008). The report would then show:
Percentage of M&A Hours
Nov-07 Dec-07 Jan-08 Feb-08 Mar-08 Apr-08
This will continue every month until we hit 12 months.
Any help/advice would be appreciated.