Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stored Procedure that adds a column every month

Status
Not open for further replies.

scoobyroo

Programmer
May 10, 2007
47
US
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.
 
This sounds like an Excel question. Your output from the server should be the same:

[tt]OtherColumn Month Value
1 Jan 07 100
5 Sep 08 75[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top