| Author |
Topic  |
|
|
allan8964
Posting Yak Master
196 Posts |
Posted - 11/16/2012 : 23:18:05
|
Hi there,
I am not sure if this is possible that automatically let a table feed a stored procedure with parameters:
tableParam has columns: ID | Year | Month | Week |
A stored procedure run as exec sp_ClculateValue year, month, week
here year, month and week are the parameters coming from table tableParam with year, month, week order. How can i let the table feed the sp with all parameters in the order of exec sp_ClculateValue 2010, Jan, week1 exec sp_ClculateValue 2010 Feb, week2 ... exec sp_ClculateValue 2010 Dec week1 ... exec sp_ClculateValue 2011, Jan, week1 ... exec sp_ClculateValue 2011, Feb, week1 exec sp_ClculateValue 2011, Dec, week1
till all values in tableParam run out? thanks in advance.
|
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47173 Posts |
Posted - 11/16/2012 : 23:22:35
|
you've to use a cursor based logic in t-sql for this
Is this requirement to do it native sql or one to call from ssis package?
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
allan8964
Posting Yak Master
196 Posts |
Posted - 11/16/2012 : 23:31:13
|
thanks visakh16 for quick reply. it's goona be called from an SSIS package. could you plz be little more specific on how to use cursor for this? If it takes much time any link will help too. thanks again. |
 |
|
|
sunitabeck
Flowing Fount of Yak Knowledge
5152 Posts |
|
|
madhivanan
Premature Yak Congratulator
India
22461 Posts |
Posted - 11/19/2012 : 04:23:39
|
Another method to do is
declare @sql varchar(max) set @sql='' select @sql=@sql+' exec sp_ClculateValue '+cast(year as varchar(4))+','+cast(month as varchar(2))+','+cast(week as varchar(4)) from table order by id select @sql
If the select gives all you want , add exec(@sql) at the end
Madhivanan
Failing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47173 Posts |
Posted - 11/20/2012 : 01:42:15
|
quote: Originally posted by allan8964
thanks visakh16 for quick reply. it's goona be called from an SSIS package. could you plz be little more specific on how to use cursor for this? If it takes much time any link will help too. thanks again.
if its called from an ssis package you can do the following
1. Create a variable of type object 2. Use an execute sql task to retrieve values from tableparam and populate the object variable 3. Use a For each loop with ADO .NET enumerator and map to above object variable 4. Create three other variables of type int to hold the Year,Month,Week values from loop during each iteration and map inside for each loop 5. Add another execute sql task inside for each loop to call the sp
make the statement as
exec sp_ClculateValue ?, ?, ?
and map to variables in parameter mapping tab as variable type direction parametername User::Year long Input 0 User::Month long Input 1 User::Week long Input 2
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
| |
Topic  |
|