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.
| Author |
Topic |
|
the_zaddik
Starting Member
3 Posts |
Posted - 2007-06-12 : 11:22:39
|
| Hello, I have a stored procedure that creates a temp table with a year of values, then goes through month by month calculating totals and percents. I want to make part of it a separate procedure, and just call it passing column names. The problem is that there are 9 columns to calculate for each month. What is the best way to iterate through the columns? (I dont want to write out the same query tons of times in one procedure)Calling Procedure like this:WHILE ( something ) BEGIN SP_FOO(SomeColumName,SomeOtherColumn,month,year)ENDThis is the text of the SP to calculate UPDATE ##TEMPTABLESET @SomeColumName= COUNTS.SURVEYSSENT, @SomeOtherColumn = COUNTS.SURVEYSSENTSCOREFROM ##TEMPTABLE SUMM, ( SELECT FROM ( SELECT FROM WHERE MONTH(DATE_SENT) = @month AND YEAR(DATE_SENT) = @year ) SENT, ( SELECT FROM WHERE REPORTMONTH = @month AND REPORTYEAR = @year ) RET WHERE) COUNTSWHERE |
|
|
rudesyle
Posting Yak Master
110 Posts |
Posted - 2007-06-12 : 15:15:36
|
| Without drinking some alcohol to decipher what you want, might this be accomplished by creating a function that returns a table? |
 |
|
|
the_zaddik
Starting Member
3 Posts |
Posted - 2007-06-12 : 16:13:00
|
quote: Originally posted by rudesyle Without drinking some alcohol to decipher what you want, might this be accomplished by creating a function that returns a table?
Rudestyle, indeed!TABLE survey_yearly_metricdatapoint1month1 int,datapoint2month1 int,datapoint3month1 int,datapoint4month1 int,datapoint5month1 int,datapoint6month1 int,and so on till month12now i have a stored proc that loads in some data to a temp table and begins calculating the values. This procedure calls another one to do some update.I want to have a way to procedurally pass datapoint1month1 column name to the nested stored procedure.Is there a way to do this? |
 |
|
|
the_zaddik
Starting Member
3 Posts |
|
|
|
|
|
|
|